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.
This is ugly but works :)
render Rails.application.routes.recognize_path(request.referer)[:action]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With