Forum: Ruby on Rails Validates_presence_of in ActionMailer model

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.
Damien (Guest)
on 2006-04-23 11:45
(Received via mailing list)
Hi all,

I want to submit the content of a form by mail.
I don't want to save it into a DB.

How can I validates the content of this form with validates_presence_of
?

Thank you.

Damien
Alex Wayne (Guest)
on 2006-04-23 20:29
Damien wrote:
> Hi all,
>
> I want to submit the content of a form by mail.
> I don't want to save it into a DB.
>
> How can I validates the content of this form with validates_presence_of
> ?
>
> Thank you.
>
> Damien

validates_presence_of is a method defined in ActiveRecord, so if you
don't have an active record object, you dont get the method.  You may
have to do manual validation of data that has no model.
Robby Russell (Guest)
on 2006-04-23 20:46
(Received via mailing list)
Damien wrote:
> Hi all,
>
> I want to submit the content of a form by mail.
> I don't want to save it into a DB.
>

May I ask why not? Does your application not use a database at all?
Storing the data in the database is a nice backup and you can still send
the email... trusting that the email gets delivered isn't as safe. ;-)

</opinion>

> How can I validates the content of this form with validates_presence_of ?

You need an ActiveRecord object in order to use the validations in
Rails.

Rick Olsen has a rails weenie entry where he defines the columns in an
ActiveRecord object without a database table... which gives you access
to those validation methods. I did something similar for a
proof-of-concept plugin for interacting with stored procedures... to
validate parameters before executing the procedure. I'm sure that this
same concept could be used in this case.

Here is the post from Rails Weenie:

   - http://rubyurl.com/UTf

Hope that helps!

Cheers,

Robby


--
Robby Russell
Founder & Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.planetargon.com
www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]
Damien (Guest)
on 2006-04-23 22:32
(Received via mailing list)
Thank you for your replies.

Yes, it helps :)

Damien
This topic is locked and can not be replied to.