make_resourceful icon indicating copy to clipboard operation
make_resourceful copied to clipboard

Not redirecting to show page after successful create / update

Open lucaspiller opened this issue 14 years ago • 3 comments

This could very well be me just not reading the docs fully, but I have spend quite a while and can't find anything.

I have a resource that doesn't require a show page (at least for HTML - which is all I care about at the moment), as such, after a create and update I want to redirect back to the parent object's show page.

I have tried adding the following, however even if the action is not successful they are still redirected. Is there anyway around this?

response_for :create, :update do
  redirect_to campaign_path(parent_object.id)
end

lucaspiller avatar Feb 26 '10 17:02 lucaspiller

If you action is not successful and you don't want to render the new/edit page again, you should use response_for :create_failed and handle it there.

For successful actions, what you have should work (I do it all the time).

look avatar Feb 26 '10 20:02 look

Thanks, that does the trick, but it isn't particularly elegant:

response_for :create, :update do
  redirect_to campaign_path(parent_object.id)
end

response_for :create_fail do
  render :action => :new
end

response_for :update_fail do
  render :action => :edit
end

It would be great if there was a :create_success action!

lucaspiller avatar Mar 01 '10 11:03 lucaspiller

There is, it's called :create.

look avatar Mar 01 '10 16:03 look