When creating an error, should I make a "new" or redirect to a "new"?

Suppose I have something like this:

def new
  @user = User.new
end
def create
  @user = User.create(params[:user])
  if @user.save
    flash[:notice] = 'User created'
    redirect_to :action => 'list'
  else
    flash[:error] = 'Some error here!'
    render 'new'
  end
end

I think the code is clear.
The problem here is that if the object was @usernot saved successfully, should I do new(as above) or redirect to new?

I know if redirecting to newlost data that the user will lose, but if I draw new, the URL will be /users/createinstead /users/new(which is ugly!).

+5
source share
1 answer

Correctly you do not use redirect. Redirection loads a completely new resource.

render , , , .

:

, , , , URL /users/create /users/new ( !).

, . render 'new', URL users/new . POST , , . new .

create update, , PUT, edit .

+2

All Articles