How do you use redirect_to when the action is depe

2019-07-30 18:31发布

How do you use redirect_to when the Edit action is dependent on a parameter being passed?

I have two very simple actions edit and update. Once I click submit, following an update I'd like to redirect the user back to the edit action. How do I do this if the edit action requires a parameter?

  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
  • this code blows up

1条回答
别忘想泡老子
2楼-- · 2019-07-30 19:08

Try the following:

 redirect_to edit_account_path( account.id, :user_id => params[:user_id])

I assume here you declared your routes as resources :accounts

查看更多
登录 后发表回答