Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render the action that initiated update

I have a SettingsController with actions account and profile, and also an update that looks like:

  def update
    @player = current_user
    if @player.update_attributes(params[:player])
      flash[:success] = "Profile updated."
      redirect_to :back
    else
      @title = "Edit"
      render
    end
end

Now the profile and account actions each have a corresponding view, with a form to edit some records of the Player model.

When you try to save one of those forms, and it fails, ie. it didn't pass validation, it should render the action that initialized the update again, so it can display appropiate error messages.

But the problem is, how do I know which of both requested the update, and render the right one? Basically some sort of equivalent of redirect_to :back is what I'm looking for here.

like image 499
Sebastian Avatar asked Mar 06 '11 00:03

Sebastian


1 Answers

This is ugly but works :)

render Rails.application.routes.recognize_path(request.referer)[:action]
like image 162
apneadiving Avatar answered Oct 17 '22 13:10

apneadiving