简体   繁体   中英

Rails_admin show text written by CKEditor with html format

I have integrated CKEditor for my rails_admin. In edit page I have added CKEditor and wrote text.

In my model showing page it shows me like that: 在此处输入图片说明

My code for show :

show do
  include_all_fields

end

What I need to add, to show my text, written on CKEditor, able to show in rails_admin?

==== UPDATE ====

I have added config.assets.precompile += %w( ckeditor/* ) code in my production.rb and development.rb . Then I have run rake assets precompile tasks and restarted my server. It still shows the same thing in my image above.

Even If it will be possible to show text in html format, it will born new question. As you can see in image, there is img tag and its src shows not full directory of my uploaded image. If I need to send this formatted text as JSON to my phone?

==== UPDATE ====

I have opened code inspector of my browser to see description part of my page. It showd me this: 浏览器代码检查器

My html code, created by CKEditor, is written well, but my browser does not consider it as html code and there is quotation marks. Does these quotation marks affect to my browser to show it as bare text?

I have found solution. I don't know is it good or not:

show do
  include_all_fields

  field :description do
    pretty_value do
      value.html_safe
    end
  end
end

Maybe your CKEditor config startupMode is settled as 'source'. Remove that if so.

During asset precompilation Ckeditor gem would compile the source from vendor/assets/ckeditor folder into the special resource package that looked like this:

$ ls public/assets/ckeditor/
application.js
application.js.gz
application-1f3fd70816d8a061d7b04d29f1e369cd.js
application-1f3fd70816d8a061d7b04d29f1e369cd.js.gz
application-450040973e510dd5062f8431400937f4.css
application-450040973e510dd5062f8431400937f4.css.gz
application.css
application.css.gz
ckeditor-b7995683312f8b17684b09fd0b139241.pack
ckeditor.pack
filebrowser
images
plugins
skins
lang

and, apparently, plain ckeditor.js was just not there. In order to provide the necessary source files I had to explicitly add them to the precompile array for the production environment in config/environments/production.rb :

> config.assets.precompile += %w( ckeditor/* )

Then run rake assets:precompile

I find another solution and for me it's working fine:

make that your config/initializers/rails_admin.rb

config.model Post do
    edit do
      field :title, :text do 
        label 'title'
      end
      field :content, :ck_editor, :text do
        label 'content'
      end
    end
  end

and your index/show

<%= raw @post.content %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM