【问题标题】:No Method Error when using ckeditor_textarea in view - Ruby on Rails 3在视图中使用 ckeditor_textarea 时没有方法错误 - Ruby on Rails 3
【发布时间】:2011-06-01 05:30:10
【问题描述】:

我正在构建一个基本的管理员区域,并希望包含一个内容编辑器,以便我的编辑人员在不了解 HTML 的情况下轻松编辑内容。我选择使用CKEditor 运行并使用RubyGemsCKEditor

我已关注 all the instructions 进行设置。

我收到以下错误。

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 />

我创建了一个管理员区域,可以在 domain/access/articles 中创建文章,并在我的路由文件中创建了嵌套资源。

routes.rb提取

  namespace "access" do
    resources :pages, :articles
  end

我已经在另一个项目中使用了这个,但我不确定为什么这次它不起作用。我必须在哪里做错了?

这是我的表单代码

<%= 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_article, :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 %>

如果我使用标准助手&lt;%= f.text_area :content %&gt;,我没有任何问题。

【问题讨论】:

  • 我刚刚意识到我需要将 gem 添加到我的 gemfile 中的开发组中。
  • f.ckeditor_textarea ?

标签: ruby-on-rails ruby-on-rails-3 ckeditor


【解决方案1】:

我找到了解决办法:不要使用CKEditor helper,使用HTML代码:

在这种情况下,字段为“post[body]”,表单为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 %>

【讨论】:

    猜你喜欢
    • 2020-11-06
    • 1970-01-01
    • 2022-08-17
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多