Rails forms: render different actions based on validation
Posted
by
Martin Petrov
on Stack Overflow
See other posts from Stack Overflow
or by Martin Petrov
Published on 2010-12-29T15:51:27Z
Indexed on
2010/12/29
15:53 UTC
Read the original article
Hit count: 141
ruby-on-rails
Is it possible to render different actions based on what fails at validation?
For example - I have one field in the form - email addres. It is validated like this:
validates :email,
:presence => true,
:uniqueness => { :case_sensitive => false }
In the controller:
def create
@user = User.new(params[:user])
if @user.save
redirect_to somewhere
else
# render :new if email is blank
# redirect_to somwhere if email is taken
end
end
© Stack Overflow or respective owner