【发布时间】:2011-02-22 15:33:16
【问题描述】:
我想让用户能够使用 rails 中的 restful_authentication 插件更改他们的帐户信息。
我将这两种方法添加到我的用户控制器中:
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
# Only update password when necessary
params[:user].delete(:password) if params[:user][:password].blank?
respond_to do |format|
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
format.html { redirect_to(@user) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
另外,我将 new.html.erb 复制到 edit.html.erb。考虑到资源已经在 routes.rb 中定义,我希望它可以轻松工作,但不知何故,当我单击保存按钮时,它会调用 create 方法,而不是 update,使用 POST HTTP 请求。 之后,它会立即自动退出会话。
有什么想法吗?
【问题讨论】:
-
可能,如果您显示您的
edit.html.erb,这将有助于了解发生了什么。
标签: ruby-on-rails rest ruby-on-rails-plugins restful-authentication