2

我在帖子中嵌入了一些图像(这是一个带有 tinymce 编辑器的文本区域)。这些图像通过 Paperclip 成功上传到 Amazon S3。我可以看到帖子显示嵌入在文本中的图像轮廓,但我无法在帖子上显示它并且图像已损坏。

谁能指导我如何在帖子上显示来自 S3 的图像?错误如下。

ActionController::RoutingError (No route matches [GET] "/posts/:id/undefined")...

如何解决路由问题

我读到了一些宝石 elfinder 和 imagemagick。我没有。他们有责任吗?或者我需要附加带有外键约束的图像模型的后模型。

_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

路线.rb

resources :posts
post '/tinymce_assets' => 'tinymce_assets#create'

配置/环境/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'
      }
  }

宝石文件.rb

gem 'tinymce-rails'
gem 'tinymce-rails-imageupload', github: 'PerfectlyNormal/tinymce-rails-imageupload'
4

0 回答 0