我有以下更新用户个人资料的内容。使用基本 url ( http://domain_name.com/users/ ) 非常好。
def update
@user = User.find(params[:id])
respond_with @user do |format|
if @user.update_attributes(params[:user])
if current_user.becomes(User) == @user
sign_in(@user, :bypass => true)
end
flash[:notice] = 'User was successfully updated.'
format.html { redirect_to @user }
format.json { render :status => :ok }
else
format.html { render :action => 'edit' }
format.json { render :status => :bad_request }
end
end
end
现在我想将它移动到管理命名空间(http://domain_name.com/admin/users/)。而我尝试的是改变
redirect_to @user
至
redirect_to admin_user_path(@user)
然后我得到:
def update
@user = User.find(params[:id])
#respond_with(@user) do |format|
respond_with(@user, :location => admin_user_path(@user)) do |format|
if @user.update_attributes(params[:user])
if current_user.becomes(User) == @user
sign_in(@user, :bypass => true)
end
flash[:notice] = 'User was successfully updated.'
format.html { redirect_to admin_user_path(@user) }
format.json { render :status => :ok }
else
format.html { render :action => 'edit', :location => edit_admin_path(user) }
format.json { render :status => :bad_request }
end
end
end
但它不起作用。我也尝试改变
respond_with(@user) do |format|
类似于
respond_with(@user, :location => admin_user_path(@user)) do |format|
但它也不起作用。谁能有经验,请给我一些建议或解释。
谢谢!