Validates_presence_of in ActionMailer model

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

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.

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. :wink:

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:

Hope that helps!

Cheers,

Robby


Robby R.
Founder & Executive Director

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

www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]

Thank you for your replies.

Yes, it helps :slight_smile:

Damien