I have some images embedded in a post(which is a textarea with tinymce editor). These images are successfully uploaded to Amazon S3 through Paperclip. I can see that the post shows the image outline embedded in the text but I'm unable to display it on the post and image is broken.
Can anyone guide me how do I display the images from S3 on the post? The error is as below.
ActionController::RoutingError (No route matches [GET] "/posts/:id/undefined")...
how to fix the routing issue
I read about some gems elfinder and imagemagick. I donot have them. Are they responsible?Or do I need to attach post model with image model with a foreign key constraint.
_form.html.erb
<%= simple_form_for @post, html: { multipart: true } do |f| %>
<%= f.input :content, as: :text, label: false, placeholder: "Add content", input_html: {class: "tinymce" } %>
<%= f.button :submit, class: 'btn btn-success btn-block'%>
<% end %>
tinymce.yml
theme: "modern"
width: "300"
height: "500"
theme_advanced_toolbar_location: top
theme_advanced_toolbar_align: left
theme_advanced_statusbar_location: bottom
theme_advanced_buttons3_add:
- tablecontrols
- fullscreen
- uploadimage, image
plugins:
- table
- fullscreen
- textcolor
- colorpicker
- codesample
- uploadimage
- link
toolbar:
- styleselect | bold italic | undo redo | uploadimage | link | codesample | forecolor | backcolor
alternate:
selector: -textarea.table-editor
relative_urls: false
tinymcecontroller.rb
class TinymceAssetsController < ApplicationController
respond_to :json
def create
geometry = Paperclip::Geometry.from_file params[:file]
image = Image.create params.permit(:file, :alt, :hint)
render json: {
image: {
height: geometry.height.to_i,
width: geometry.width.to_i
}
}, content_type: "text/html"
end
end
routes.rb
resources :posts
post '/tinymce_assets' => 'tinymce_assets#create'
config/environment/development.rb
config.serve_static_files = true
#S3 with paperclip settings
config.paperclip_defaults = {
storage: :s3,
s3_host_name: 's3-eu-west-2.amazonaws.com',
s3_credentials: {
bucket: 'projDB',
access_key_id: 'aaa',
secret_access_key: 'xxx',
s3_region: 'eu-west-2'
}
}
Gemfile.rb
gem 'tinymce-rails'
gem 'tinymce-rails-imageupload', github: 'PerfectlyNormal/tinymce-rails-imageupload'