# Validation for a non active record input field

**URL:** <https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388>\
**Category:** Rails\
**Created:** [March 19, 2009, 7:29pm UTC](https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388 "2009-03-19T19:29:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [March 19, 2009, 7:29pm UTC](https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388/1 "2009-03-19T19:29:39Z")

</div>

I am developing a classifieds type application. It has a Classified  
Model, Classified controller and a “show” view.

When viewing an ad, it has an option to reply to the advertiser through  
action mailer. This reply is a form that contains 2 text fields ( email  
and message) not connected to any table.

How do i validate this email and message?. I was told that  
attr\_accessor can be used but this doesn’t work quite well as I am  
unable use it in Classified Model because when an advertiser edit’s  
his/her ad, it throws a validation that “Message” cannot be blank ( this  
message field is the one that should be used for replying to the  
advertiser).

any idea is much appreciated.

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [March 21, 2009, 5:42pm UTC](https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388/2 "2009-03-21T17:42:39Z")

</div>

not even a single person implemented non-active record field  
validation?..please help

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [March 22, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388/3 "2009-03-22T21:50:44Z")

</div>

Hi there,

I’ve never done something like that but I can imagine you could do the  
validation in your controller. When the action is invoked you can  
check the values received in the params hash and act accordingly.

Pepe

On Mar 21, 12:42 pm, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [March 23, 2009, 7:06pm UTC](https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388/4 "2009-03-23T19:06:43Z")

</div>

pepe wrote:

> Hi there,
> 
> I’ve never done something like that but I can imagine you could do the  
> validation in your controller. When the action is invoked you can  
> check the values received in the params hash and act accordingly.
> 
> Pepe
> 
> On Mar 21, 12:42ï¿½pm, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks a million. Worked as I wanted (how did I miss this approach?)  
🙂

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [March 24, 2009, 10:00pm UTC](https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388/5 "2009-03-24T22:00:48Z")

</div>

🙂

On Mar 23, 2:06 pm, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [March 25, 2009, 4:39pm UTC](https://www.ruby-forum.com/t/validation-for-a-non-active-record-input-field/163388/6 "2009-03-25T16:39:40Z")

</div>

What you should have is a new model (e.g. AdReply), so that that form  
points to AdRepliesController#create, which then attempts to create  
the model, and redirects wherever you need to if successful/failed.  
All the validations are then on that model and are independent of your  
ClassifiedModel.

Cheers,

– D
