希望有人能指出我正确的方向.
我有一个控制器Update def运行"update_attributes".目前它返回false,没有错误消息.我对Ruby很新,但不是编码,这让我难以忍受了好几天!我试图使用下面指定的值更新用户模型和数据库.
def update
#get currently logged in user
@user = current_user
#update user params based on edit form...
if @user.update_attributes(params[:user])
redirect_to profile_path, :notice => "Successfully updated profile."
else
render :action => 'edit'
end
end
Run Code Online (Sandbox Code Playgroud)
我的编辑def ....
def edit
@user = current_user
end
Run Code Online (Sandbox Code Playgroud)
表单将以下内容发送到此更新方法:
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
utf8: ?
_method: put
authenticity_token: 9T4ihVI0p8j7pZEFxof3Bfahi2a+o3BPmtXJDnfHT4o=
user: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
first_name: Amanda
last_name: Ross
is_owner: '1'
email: example@googlemail.com
commit: Update
action: update
controller: users
id: '20'
Run Code Online (Sandbox Code Playgroud)
并且params [:user]返回:
{"first_name"=>"Amanda", "last_name"=>"Ross", "is_owner"=>"1", "email"=>"example@googlemail.com"}
Run Code Online (Sandbox Code Playgroud)
所有这些字段都在模型中的attr_accessible中,我可以毫无问题地创建用户.
这里是development.log输出(对不起它有点乱)....
Started …Run Code Online (Sandbox Code Playgroud) ruby controller ruby-on-rails update-attributes ruby-on-rails-3