Hi,
I want to do a simple thing: Validate a form so it raises an error when a field is empty. The thing is that I don't save the contents of that form into DB.
What I've done is:
1- Add model like this:
class Password < ActiveRecord::Base validates_presence_of :email, :on => :create end
2- The view is:
<%= error_messages_for :password %> <% form_for :password, :url => { :action => 'create' } do |f| %> What was the email address used to create your account?<br/><br/> <%= f.text_field :email, :size => "50" %> <%= submit_tag 'Reset Password' %> <% end %>
3- The controller is:
... def create @user = User.find_for_forget(params[:email]) return unless request.post? if @user = User.find_for_forget(params[:email]) @user.forgot_password @user.save redirect_to login_path else render :action => 'new' end end
4- And my problem is that I get no errors (from the system) when I press the button in the form. Shouldn't it validate it when the create method is called?
I didn't generate the model I just added the password.rb to use the validate utilities.
Again, I just want to see the error that rails has by default.
Thanks for any hints you might have.