我正在使用多步表单(使用 Wicked gem)。在表单的前几个步骤中,我正在编辑用户模型,这些步骤工作正常。然后我尝试与用户模型具有 HABTM 关系的“兴趣”模型。但是我收到此错误:
ActiveModel::MassAssignmentSecurity::Error in UserStepsController#update
Can't mass-assign protected attributes: interest_ids
Rails.root: /Users/nelsonkeating/rails_projects/Oreminder1
Application Trace | Framework Trace | Full Trace
app/controllers/user_steps_controller.rb:12:in `update'
user_steps_controller.rb
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :standard, :personal, :interests, :dates
def show
@user = current_user
render_wizard
end
def update
@user = current_user
@user.attributes = params[:user]
render_wizard @user
end
end
观点如下:
<%= render layout: 'form' do |f| %>
<% for interest in Interest.find(:all) %>
<label class="checkbox">
<%= check_box_tag "user[interest_ids][]", interest.id, @user.interests.include?(interest) %>
<%= interest.name %>
</label>
<% end %>
<% end %>
有任何想法吗?谢谢!