Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CKEditor on a field in rails_admin?

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.

like image 685
dexter Avatar asked Dec 31 '10 20:12

dexter


3 Answers

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.

like image 99
tomcocca Avatar answered Oct 05 '22 22:10

tomcocca


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

like image 34
Robbie Done Avatar answered Oct 06 '22 00:10

Robbie Done


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!

like image 29
B. Bulpett Avatar answered Oct 05 '22 23:10

B. Bulpett