REST vs. render vs. redirect_to w.r.t. create error messages


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 where there is a
form that POSTs the data to the user/create action. The controller
might look like

def new
@user =

def create
@user =[: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 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

GET /people;new

def new() end

POST /people

def create() end

If the create fails what will the URL be in the browser?

How do you handle this URL issue?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs