当操作依赖于传递的参数时,如何使用redirect_to?
当Edit操作依赖于传递的参数时,如何使用redirect_to?
我有两个非常简单的动作编辑和更新。 点击提交后,在更新后我想将用户重定向回编辑操作。 如果编辑操作需要参数,我该怎么做?
def edit @account = Account.find_by_user_id(@params['user_id']) end def update account = Account.find(params[:account_user_id]) if account.update_attributes(params[:name]) redirect_to params[:user_id].merge!(:action => :edit) else render :text => 'Sorry there was an error updating.' end end
- 这段代码爆炸了
请尝试以下方法:
redirect_to edit_account_path( account.id, :user_id => params[:user_id])
我假设你在这里宣布你的路线是resources :accounts