How to enable CKEditor in a field in rails_admin?

I am new to rails and recently I discovered rails_admin.

I added CKEditor using the command from the rails_admin documentation, but I don’t know how to include it in the field.

+7
source share
4 answers

It was just necessary to understand this today. This is how I earned it. In my config / initializers / rails_admin.rb, I have the following setting.

config.model MyModel do edit do field :description, :text do ckeditor do true end end end end 

Change "MyModel" to your model name and ": description" with the name of the field you want to use ckeditor in. Also in the edit box, make sure that you have all your other field settings.

Update

The syntax above is deprecated in new versions of rails_admin.

 config.model MyModel do edit do configure :name, :ck_editor end end 

- new syntax for this.

+12
source

To make sure all fields show, add this to your rails_admin.rb:

  config.model Car do include_all_fields field :content, :text do ckeditor true end end 

Hi

Robbie

+2
source

Well, anyone reading this after 2015, the above solution is outdated and will lead to a runtime error. I tried and got the following error:

The style "field (: foo) {ckeditor true}" DSL style is deprecated. Instead, use the field: foo ,: ck_editor.

So, with the new syntax, it looks like this:

 config.model MyModel do edit do field :description, :ck_editor, :text do label 'MyLabel' end end end 

By the way, this works fine if you omit :text from the arguments. This solution was tested using rails-4.0.2, rack-pjax-0.8.0 and ckeditor-4.1.4. Good luck

+1
source

@Kris, @tomcocca

I did the above snippet as tomcocca showed, but I had one serious problem. The problem was that when I ran rake db: drop db: create db: migrate, rails would throw errors because the table was not initialized yet.

The second problem was that when you defined such a model, you need to subsequently define each field. therefore, only the “description” is displayed in this case, unless you add other fields.

Regarding the first problem, the author of this gem answered my problem and wrote:

Ruby on rails, run the method on server 2.3. Maybe this should be included in RailsAdmin? Can you work with a tensile request?

re: pull request (working on it)

but this solution works for both of my problems:

 config.models do fields_of_type :text do ckeditor true end end 

Thus, ckeditor is loaded into all my text fields, plus all the other model fields, plus I do not understand the problem with rake db: drop db: create ...

0
source

All Articles