ActiveModel::ForbiddenAttributesError in PasswordResetsController#update [英] ActiveModel::ForbiddenAttributesError in PasswordResetsController#update

查看:28
本文介绍了ActiveModel::ForbiddenAttributesError in PasswordResetsController#update的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过瑞恩铁路广播第 274 集我正在使用 rails 4 并遇到一个问题.

I have seen Ryan railcasts episode 274 I am using rails 4 and encountered one problem.

在 password_resets_controller.rb 中

In password_resets_controller.rb

elsif @user.update_attributes(params[:user])

在控制台显示

ActiveModel::ForbiddenAttributesError in PasswordResetsController#update

当我将 update_attributes 修改为 update_attribute 时,它显示

when I modified update_attributes to update_attribute it shows

wrong number of arguments (1 for 2)

params[:user] 显示两个值 passwordpassword_confirmation 但我在登录时使用 password

params[:user] showing two value password and password_confirmation but i am using password in my login page

我不知道如何解决这个问题.

I do not know how to solve this issue.

推荐答案

这是因为 Rails 4 中的强参数特性.使用禁止属性进行批量赋值时会引发.

This is because of Strong parameters feature in Rails 4. It will be raised when forbidden attributes are used for mass assignment.

您必须允许控制器中的属性.像这样

You have to permit the attributes in your controller. Like this

@user.update_attributes(params.require(:user).permit(:password, :password_confirmation))

这篇关于ActiveModel::ForbiddenAttributesError in PasswordResetsController#update的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆