I couldn’t figure out why this happens after stumbling around Michael Hartl tutorial.
When I click the submit form and expect fail, the expected url after rendering should be ‘/signup’ but some reasons it is ‘/users’
This is my controller
def new
@user = User.new
end
def show
@user = User.find(params[:id])
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to @user
else
render 'new'
end
This is my routes
resources :users
match '/signup', to: 'users#new'
First of all when I click the signup link the url is
http://localhost:3000/signup
Then submisson fails this url is
http://localhost:3000/users
Could anyone explain me why it happens ? Thanks
When you are posting to the UsersController (to create a new user, from your signup action), you’re invoking the
#createaction. If you view source on that page, you’ll see that the form action is/usersand the form method isPOST. So when you submit the form, the request made is:If the save fails, then your create action there just renders the “new” template. You don’t get redirected anywhere.
render :action => "new"just renders the template for thenewaction – it doesn’t actually redirect to the new action, or run its action code.