Forum: Ruby on Rails Validation that works in the controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
757e0ccb6005344ecbc8c096744183b7?d=identicon&s=25 Colin JN Breame (Guest)
on 2005-12-19 12:01
(Received via mailing list)
Hi,

Is there a way of validating input inside the controller? or an
equivalent to
ActiveRecord::Validations::ClassMethods.validates_presence_of ?

Cheers,

 -- Colin
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2005-12-19 15:53
(Received via mailing list)
just override the validate method

class Foo < ActiveRecord::Base
  def validate
    errors.add(:name, "is blank") if name.nil? or name == ""
    # other validations
  end
end

then you can call @user.valid? at any time

http://rails.rubyonrails.com/classes/ActiveRecord/...
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2005-12-19 16:41
(Received via mailing list)
On 12/19/05, Chris Hall <christopher.k.hall@gmail.com> wrote:
>
> http://rails.rubyonrails.com/classes/ActiveRecord/...
>
>
> On 12/19/05, Colin JN Breame <colin@breame.net > wrote:
> > Hi,
> >
> > Is there a way of validating input inside the controller? or an equivalent
> to
> >
> ActiveRecord::Validations::ClassMethods.validates_presence_of

I have a Rails Weenie tip for validating non-model data.  It basically
creates a table-less model you can use for a form:

http://rails.techno-weenie.net/tip/2005/11/19/vali...


--
rick
http://techno-weenie.net
This topic is locked and can not be replied to.