I'm new to rails and I recently discovered rails_admin.
I added CKEditor using the command from rails_admin documentation, but I don't know how to enable it on a field.
Just had to figure this out today. This is how I got it to work. In my config/initializers/rails_admin.rb I have the following set up.
config.model MyModel do
edit do
field :description, :text do
ckeditor do
true
end
end
end
end
Change 'MyModel' with the name of your model and ':description' with the name of the field you want to use ckeditor on. Also in the edit block make sure that you have all of your other field config.
Update
The syntax above has been deprecated in newer versions of rails_admin.
config.model MyModel do
edit do
configure :name, :ck_editor
end
end
is the new syntax of doing it.
To make sure all the fields show add this to your rails_admin.rb:
config.model Car do
include_all_fields
field :content, :text do
ckeditor true
end
end
Regards
Robbie
Ok anyone reading this after 2015, the above solution is deprecated and will produce a runtime error. I tried it and got the following error:
The 'field(:foo){ ckeditor true }' style DSL is deprecated. Please use 'field :foo, :ck_editor' instead.
So, with the new syntax it's like this:
config.model MyModel do
edit do
field :description, :ck_editor, :text do
label 'MyLabel'
end
end
end
Incidentally, this works just fine if you omit :text
from arguments.
Tested this solution with rails-4.0.2, rack-pjax-0.8.0, and ckeditor-4.1.4. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With