How can I use action text on active admin

浪尽此生 提交于 2020-12-29 11:58:32

问题


i'm using rails 6.0.0 and ruby 2.6.0, I want to know what's the best way to use ActionText in ActiveAdmin, should I have to use render?


回答1:


I used this f.rich_text_area :content inside ActiveAdmin but it didn't work for me so I added <trix-editor> tag inside a custom form following this Form Partial Tricks but also this didn't work so I ended up using this gem ActiveAdmin Quill Editor it was easy to setup and worked perfectly

Install

  • Add this to your Gemfile gem 'activeadmin_quill_editor'

  • in your app/assets/stylesheets/active_admin.scss file, add this:

@import 'activeadmin/quill_editor_input';
  • in your app/assets/javascripts/active_admin.js file, add this:
//= require activeadmin/quill_editor/quill
//= require activeadmin/quill_editor_input

Example

# ActiveAdmin article form conf:
  form do |f|
    f.inputs 'Article' do
      f.input :title
      f.input :description, as: :quill_editor
      f.input :published
    end
    f.actions
  end



回答2:


Add this to your Gemfile

gem 'activeadmin_quill_editor'

in your app/assets/stylesheets/active_admin.scss

@import 'activeadmin/quill_editor/quill.snow';
@import 'activeadmin/quill_editor_input';

in your app/assets/javascripts/active_admin.js

//= require activeadmin/quill_editor/quill
//= require activeadmin/quill_editor_input

app/admin/posts.rb

ActiveAdmin.register Post do
  permit_params :title, :text, :tag_list
  form do |f|
    f.inputs 'Article' do
      f.input :tag_list, :input_html => {:value => f.object.tag_list.join(", ") }, :label => "Tags (separated by commas)".html_safe
      f.input :title
      f.input :text, as: :quill_editor, input_html: { data:
        { options:
          { modules:
            { toolbar:
              [%w[bold italic underline strike],
               %w[blockquote code-block],
               [{ 'list': 'ordered' }, { 'list': 'bullet' }],
               [{ 'align': [] }],
               ['link'],
               [{ 'size': ['small', false, 'large', 'huge'] }],
               [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
               [{ 'indent': '-1' }, { 'indent': '+1' }],
               [{ 'direction': 'rtl' }],
               [{ 'color': [] }, { 'background': [] }],
               [{ 'font': [] }],
               ['clean'],
               ['image'],
               ['video']] },
            theme: 'snow' } } }
      # f.input :published
    end
    f.actions
  end
end

It works.



来源:https://stackoverflow.com/questions/57886802/how-can-i-use-action-text-on-active-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!