【发布时间】:2012-07-15 16:37:59
【问题描述】:
我正在使用 simple_form,我只想使用分类表在类别和文章之间创建关联。
但是我有这个错误: 无法批量分配受保护的属性:category_ids。 app/controllers/articles_controller.rb:36:in `update'
articles_controller.rb
def update
@article = Article.find(params[:id])
if @article.update_attributes(params[:article]) ---line with the problem
flash[:success] = "Статья обновлена"
redirect_to @article
else
render :edit
end
end
article.rb
has_many :categorizations
has_many :categories, through: :categorizations
category.rb
has_many :categorizations
has_many :articles, through: :categorizations
categorization.rb
belongs_to :article
belongs_to :category
分类有 article_id 和 category_id 字段。
我的 _form.html.erb
<%= simple_form_for @article, html: { class: "form-horizontal", multipart: true } do |f| %>
<%= f.error_notification %>
<%= f.input :title %>
<%= f.association :categories %>
<%= f.input :teaser %>
<%= f.input :body %>
<%= f.input :published %>
<% if @article.published? %>
<%= f.button :submit, value: "Внести изменения" %>
<% else %>
<%= f.button :submit, value: "Опубликовать" %>
<% end %>
<% end %>
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 associations nested-forms simple-form