【发布时间】:2013-12-27 17:14:37
【问题描述】:
我遵循 Railscast 将应用程序迁移到 Rails 4 并转换到强参数。 http://railscasts.com/episodes/415-upgrading-to-rails-4
我的 Create/New 方法运行良好。但是,当我尝试更新记录时遇到问题。我不断收到以下消息:
CustomersController#update 中的参数错误 未知键:first_name
我查看了 Stack Overflow 上的各种帖子,还生成了一个新的 Rails 4 应用程序来验证我做的事情是否正确。我显然错过了一些东西。
这是我的更新方法的控制器代码:
def update
@customer = Customer.find(customer_params)
respond_to do |format|
if @customer.update(customer_params)
format.html { redirect_to @customer, notice: 'Customer was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @customer.errors, status: :unprocessable_entity }
end
end
end
这里是我设置强参数的地方:
private
def set_customer
@customer = Customer.find(params[:id])
end
def customer_params
params.require(:customer).permit(:first_name, :middle_initial, :last_name, :address1, :address2, :city, :state, :zip, :phone, :gender, :email, :membership_id, :date_of_birth)
end
非常感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 strong-parameters