开发者

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

开发者 https://www.devze.com 2023-03-23 20:57 出处:网络
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 redirec

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

开发者_JAVA技巧  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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消