0

我有以下代码:

控制器

def update
  @group = Group.find(params[:id])
  @group_func = @group.functionalities
  @functionalities_all = Funcionalidade.all
  @func = params[:group][:update]

  unless @group_func.include?(@func) do
    @group_func << @func
  end
end

看法

<div class="field">
    <% options = @functionalities_all.collect{|f| [f.name, f.id]} %>
    <%= f.select(:update, options, { :include_blank => true, :selected => nil}) %>
    <%= button_to "Add" %>
</div>

当我向组 Rails 添加功能时,返回此错误:

ActiveModel::MassAssignmentSecurity::GruposController#update 中的错误

无法批量分配受保护的属性:更新

如果我尝试将 :update 添加到 Model 返回此错误:

未知属性:更新

有没有人遇到过类似的错误?

4

1 回答 1

0

In your Group Model, add the following code.

attr_accessible :update

Rails naturally protects attributes from being assigned without being unprotected first. attr_accessible unprotects them so you can modify them in your controller. If you want all your attributes to be modifiable, add attr_protected to your model.

于 2013-05-07T18:37:03.107 回答