Rails 5活动管理员和丰富宝石

时间:2018-08-31 14:32:32

标签: ruby-on-rails-5 activeadmin rich-text-editor

我有一个已经运行了4年的应用程序,现在我将其更新为Ruby 2.5.1和Rails 5.2.1。在Active Admin中,丰富的宝石抛出了一个我无法解决的错误:

NoMethodError - undefined method `fetch' for nil:NilClass:
app/admin/episode.rb:16:in `block (3 levels) in <main>'
app/admin/episode.rb:13:in `block (2 levels) in <main>'

指向文本输入的富标记:

e.input :description, :as => :rich

..它指向Rich宝石中的to_html:

if (Object.const_defined?("Formtastic") && Gem.loaded_specs["formtastic"].version.version[0,1].to_i > 1)

  class RichInput < ::Formtastic::Inputs::TextInput
    def to_html

      scope_type = object_name
      scope_id = object.id
      editor_options = Rich.options(
                                    options[:config], 
                                    options[:config].fetch(:scope_type, scope_type),
                                    options[:config].fetch(:scope_id, scope_id)
                                  )

      input_wrapping do
        label_html <<
        builder.text_area(method, input_html_options) <<
        "<script>CKEDITOR.replace('#{dom_id}', #{editor_options.to_json.html_safe});</script>".html_safe
      end
    end
  end

end

我不明白的是这里发生了什么;使用更好的错误:

> Rich
=> Rich
>> scope_type
=> "episode"
>> object_name
=> "episode"
>> editor_options
=> nil
>> Rich.options
=> {:height=>400, :stylesSet=>[], :extraPlugins=>"stylesheetparser,richfile,mediaembed,showblocks", :removePlugins=>"scayt,image,forms", :contentsCss=>"/assets/rich/editor-42de41660ecb8589241e63f28d29012a692a50835f56250efb56e53d86d624aa.css", :removeDialogTabs=>"link:advanced;link:target", :startupOutlineBlocks=>true, :forcePasteAsPlainText=>true, :format_tags=>"h3;p;pre", :toolbar=>[["Styles", "Format", "Font", "FontSize"], ["Bold", "Italic", "Underline", "Strike", "Subscript", "Superscript"], ["JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock"], ["TextColor", "BGColor"], ["RemoveFormat"], ["NumberedList", "BulletedList", "Blockquote"], ["Link", "Unlink"], ["richImage"], ["Source", "ShowBlocks"]], :language=>:en, :richBrowserUrl=>"/rich/files/", :uiColor=>"#f4f4f4", :allowed_styles=>[:thumb, :large, :node, :rich_thumb, :original], :default_style=>:thumb, :insert_many=>false, :allow_document_uploads=>false, :allow_embeds=>false, :placeholder_image=>"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==", :preview_size=>"100px", :hidden_input=>false, :paginates_per=>34}
>> options[:config]
=> nil
>>
>> options
=> {:as=>:rich}

好像没有加载丰富的配置文件?肯定在那里(下)。我的想法是,如果未加载,我可以在此处添加小的简单配置,否?无论如何,我已经分叉致富:

require "rich"

if Object.const_defined?("Rich")
  Rich.setup do |config|    

    # == CKEditor configuration
    # 
    # Rich ships with what I hope are sensible defaults. 
    # You may want to override these.
    # 
    # For example, the elements available in the formats
    # dropdown are defined like this:
    #   config.editor[:format_tags] = "h3;p;pre"
    # 
    # By default, Rich visualizes what type of element
    # you are editing. To disable this:
    #   config.editor[:startupOutlineBlocks] = false


    # == Image styles
    # 
    # Rich uses paperclip for image processing. You can
    # define the styles you would like to use here. You 
    # can use the standard syntax allowed by paperclip.
    # See: https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation
    # 
    # When you change these after uploading some files,
    # remember to re-generate your styles by running:
    #   rake rich:refresh_assets
    config.image_styles = {
      :thumb => "100x100#",
      :large => "300x300>", 
      :node => "250x250>"
    }

    # == Convert options
    #
    # You can pass additional commands to ImageMagick to set image quality,
    # apply a blur, and other fancy tricks.
    #
    # Example (this will make your image look terrible):
    # config.convert_options = {
    #     :large => '-quality 1'
    # }

    # == Allowed styles (in file manager)
    # 
    # Of the styles specified above, which should be user
    # selectable in the file manager?
    #
    # Example:
    #   config.allowed_styles = [ :large, :thumb ]
    #
    # Default:
    config.allowed_styles = :all

    # == Default Style
    # 
    # The style to insert by default. In addition to the
    # styles defined above you can also use :original to get 
    # the unprocessed file. Make sure this style exists.
    config.default_style = :thumb

    # == Upload non-image files
    #
    # Setting this option to true will add a second Rich filebrowser icon to
    # the editor toolbar. In this filebrowser you can upload non-image files.
    # Inserting these files into your editor will result in a direct (A) link.
    #
    # Default:
    # config.allow_document_uploads = false

    # == Set allowed filetypes for non-image files
    #
    # If you want, you can restrict the types of documents that users can upload.
    # Default behavior is to allow any kind of file to be uploaded. You can set
    # the accepted types by providing an array of mimetypes to check against.
    # Note that for this to have any effect, you first need to enable document
    # uploads using the setting above.
    # 
    # Default, allow any file to be uploaded:
    # config.allowed_document_types = :all
    #
    # Example, only allow PDF uploads:
    # config.allowed_document_types = ['application/pdf']

    # == Asset insertion
    #
    # Set this to true to keep the filebrowser open after inserting an asset.
    # Also configurable per-use from within the filebrowser.
    #
    # Default:
    # config.insert_many = false

    # == User Authentication
    #
    # When defined, Rich will automatically call this method
    # in a before filter to ensure that the user is logged in.
    # 
    # If you do not change this value from the default, anyone
    # will be able to see your images, and upload files.
    # 
    # Example for Devise with an AdminUser model:
      config.authentication_method = :authenticate_admin_user!
    # 
    # Default (NOT recommended in production environments): 
    # config.authentication_method = :none

  end

  Rich.insert
end

0 个答案:

没有答案