Forum: Ruby on Rails Validation not working.......

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Prashant T. (Guest)
on 2006-03-17 06:44
I am new to ruby. I am developing small application in ROR. Following is
code for my rHtml , Controller & Model. PLease see it & let me know why
data in form is not get validated & also how to check for whether data i
have entered in form (username) is present in database or not? (Like
Login form).
following is my code:-
<%= start_form_tag(:action => "login")%>
<%=text_field("user", "name", "size" => 20)%>
<%=password_field("user", "password", "size" => 20)%>
<%= submit_tag %>
<%= end_form_tag %>
  def login
	  @user =[:user])
	  redirect_to :action => 'list'

 def new
    @user =
class User < ActiveRecord::Base
	validates_presence_of :name

In Above Form I want when user enters "name" field blank ihn form it
should give error message of validation.

Thanks in advance.
Craig W. (Guest)
on 2006-03-17 07:09
(Received via mailing list)
On Fri, 2006-03-17 at 05:44 +0100, Prashant T. wrote:
> <%=password_field("user", "password", "size" => 20)%>
>     @user =
I don't see any problem there...that looks good. If there's a problem
(and you didn't say there is), the problem is likely how you handle
errors in your controller...

and of course, I don't know what new.rhtml looks like.

Steve R. (Guest)
on 2006-03-17 07:42
(Received via mailing list)
The problem is that you haven't asked if it is valid:

 def login
          @user =[:user])
          if @user.valid?
            redirect_to :action => 'list'
            return # cuz you can only redirect once per action
            flash[:error] = 'something bad happened'
            render :action => 'index'

My (untested) code is dismal because neither code path displays a
template (which would be new.rhtml) relying on redirects or renders
Consider using a before_filter to do your login as described nicely in

If you'd like to see some straightforward Rails code, do a
scaffold MyTable' and you'll see how the paradigm works with new/create
View this message in context:
Sent from the RubyOnRails Users forum at
This topic is locked and can not be replied to.