저는 simple_form을 사용하고 있으며 분류 테이블을 사용하여 범주와 아티클 간의 연관성을 만들고 싶습니다.보호 된 속성을 대량 지정할 수 없습니다. category_ids
하지만이 오류가 있습니다 : 보호 속성을 지정할 수 없습니다 : category_ids. 응용 프로그램/컨트롤러/articles_controller.rb : 36 : '갱신'
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
,515,
categorization.rb
belongs_to :article
belongs_to :category
article_id를 범주화 및 CATEGORY_ID 필드를 갖는다.
<%= f.association :categories %>
만든
내 _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 %>
안녕하세요, 감사합니다! 그게 내가 attr_accessible했다 : category_id 대신에 : category_ids –