I have the following routes defined for my app:
match '/signup', :to => 'users#new'
resources :users开发者_如何转开发
Both work fine, but if I go to /signup, purposefully don't fill in the form (so that validation errors kick in), I am presented with the form (and errors), but the URL is now /users. I have tried adding ", :except => [:new]" to my :users resource, but that didn't help.
My users controller is:
def new
@user = User.new
@title = 'Sign Up'
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = 'Welcome to To Horse!'
redirect_to @user
else
@title = 'Sign Up'
@user.password = nil
@user.password_confirmation = nil
render 'new'
end
end
I'm sure I'm missing something really basic, but can't think what. Thanks!
I could be wrong, as I'm fairly new to rails myself... But I believe that instead of "render 'new'" you should probably redirect back to the new url with whatever alert/flash you want to use.
精彩评论