No Method Error when using ckeditor_textarea in view - Ruby on Rails 3
I'm building a basic administrator area and want to include a content editor for my editors to easily edit content without knowing HTML. I've chosen to run with CKEditor and used RubyGems's CKEditor.
I've followed all the instructions for setting this up.
I get the following error.
undefined method `content' for nil:NilClass
21: </div>
22: <div class="field">
23: <%= f.label :content %><br />
24: <%= ckeditor_textarea(:access_article, :content, :width => '100%', :height => '200px') %>
25: </div>
26: <div class="field">
27: <%= f.label :seo_title %><br />
I have created an administrator area where articles can be created at domain/access/articles and created the nested resource in my routes file.
routes.rb
extract
namespace "access" do
resources :pages, :articles
end
I've had this working on another project, but I am not sure why it's not working this time. Where must I be doing something wrong?
Here's my form code
<%= form_for([:access, @access_article]) do |f| %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :permalink %><br />
<%= f.text_field :permalink %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= ckeditor_textarea(:access_a开发者_开发知识库rticle, :content, :width => '100%', :height => '200px') %>
</div>
<div class="field">
<%= f.label :seo_title %><br />
<%= f.text_field :seo_title %>
</div>
<div class="field">
<%= f.label :seo_description %><br />
<%= f.text_area :seo_description, :rows => 6 %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
If I use the standard helper, <%= f.text_area :content %>
, I don't have any problems.
I found a solution: do not to use the CKEditor helper, use HTML code:
In this case field is "post[body]", and form is f
.
<%= form_for([@trek,@trek.posts.build],:remote=>true) do |f| %>
...
...
<%= f.text_area :body %>
<script type="text/javascript">
CKEDITOR.replace( 'post[body]' );
</script>
<%= ckeditor_ajax_script %>
精彩评论