Something has been bothering me for a long time and I’d like to know
what other think about this common situation with Rails.
Someone is looking at http://example.com/user/new where there is a
form that POSTs the data to the user/create action. The controller
might look like
@user = User.new
@user = User.new(params[:entry])
flash[:notice] = “User was successfully created”
redirect_to :action => “list”
render :action => ‘new’
If the create action recieves invalid data and the “.save” fails then
the the form will be redisplayed with the error messages just like we
want. But the URL will be http://example.com/user/create which is
wrong. If this address is bookmarked in the browser, the bookmark
won’t work as expected if used. The user would probably expect to see
the empty form but will see a form of errors or be redirect to the
list view if verify POST is being used for the create action.
Another option is to use a redirect_to :action => new instead of
render but this requires an extra back and forth to the browser and
the data and error messages won’t be displayed. But the URL will be
Another option is to have the create logic inside the new action. This
works but the code is not very modular.
Now I see that DHH has proposed on one of his “World of Resources”
slides using actions like the following
def new() end
def create() end
If the create fails what will the URL be in the browser?
How do you handle this URL issue?