Skip to content
SammyLin edited this page Sep 18, 2012 · 1 revision

Because use redactorjs in RailsAdmin need overwrite the gem code, so i use partials.

create partials call _form_redactor.html.erb

$ touch app/views/rails_admin/main/_form_redactor.html.erb

Then paste the code

<%= form.send :text_area, field.method_name, :class => 'redactor' %>
<link rel="stylesheet" type="text/css" href="/assets/redactor-rails/css/redactor.css" />
<script media="all" src="/assets/redactor-rails/redactor.min.js?body=1" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(
  function(){
  var csrf_token = $('meta[name=csrf-token]').attr('content');
  var csrf_param = $('meta[name=csrf-param]').attr('content');
  var params;
  if (csrf_param !== undefined && csrf_token !== undefined) {
    params = csrf_param + "=" + encodeURIComponent(csrf_token);
  }
  $('.redactor').redactor(
    { "imageUpload":"/redactor_rails/pictures?" + params,
      "imageGetJson":"/redactor_rails/pictures",
      "autoresize": false,
      "path":"/assets/redactor-rails",
      "css":"style.css"}
  );
});
</script>

in rails_admin.rb

   config.model Page do    
     edit do
       field :title     
       field :content, :text do
         partial 'form_redactor'   
       end
     end
   end

then you can word....ya~