2013-02-14 62 views
0

我试图从窗体中的某些复选框获取值。形式:从复选框获取值Ruby on Rails,多对多

<%= form_for @book do |f| %> 

    <%= f.label :title %> 
    <%= f.text_field :title %> 

    <%= f.label :description %> 
    <%= f.text_area :description %> 


<% @users.each do |user| %> 
    <%= check_box_tag 'user_ids[]', user.id,false -%> 
    <%= h user.name -%> 
    <% end %> 

<%= f.submit "Save" %> 

<% end %> 

has_and_belongs_to_many用户,所以我想要做的是从复选框中添加user ids@book.users。我怎样才能做到这一点?我不断收到错误:Can't mass-assign protected attributes: user_ids.

回答

0

在模型中加入这行并尝试

attr_accessor :user_ids