I’m using simple_form, and I just want to create association between categories and articles using categorization table.
But I have this error:
Can’t mass-assign protected attributes: 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
categorization has article_id and category_id fields.
My _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 %>
do you have attr_accessible in article.rb?
if so add
Also make sure you really want this for all forms… If not add this:
then
or