# ActiveRecord validations and FormBuilder

**URL:** <https://www.ruby-forum.com/t/activerecord-validations-and-formbuilder/62483>\
**Category:** Rails\
**Created:** [June 5, 2006, 2:27pm UTC](https://www.ruby-forum.com/t/activerecord-validations-and-formbuilder/62483 "2006-06-05T14:27:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jon\_Evans](https://www.ruby-forum.com/u/Jon_Evans)\
**Post date:** [June 5, 2006, 2:27pm UTC](https://www.ruby-forum.com/t/activerecord-validations-and-formbuilder/62483/1 "2006-06-05T14:27:48Z")

</div>

Hi,

I’m writing my own FormBuilder and I wanted to put an asterisk or  
something next to any required fields. The Builder has access to the  
AR object, is there any method I can call on the AR object that will  
tell me whether or not a particular field is required? Failing that,  
can I access the complete list of validations so I can look through  
it for instances of validates\_presence\_of?

Jon

---

<div class="post-metadata">

**Author:** ![Jon\_Evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jon\_Evans](https://www.ruby-forum.com/u/Jon_Evans)\
**Post date:** [June 5, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/activerecord-validations-and-formbuilder/62483/2 "2006-06-05T20:45:57Z")

</div>

On 5-jun-2006, at 14:25, Jon Evans wrote:

> Hi,
> 
> I’m writing my own FormBuilder and I wanted to put an asterisk or  
> something next to any required fields. The Builder has access to  
> the AR object, is there any method I can call on the AR object that  
> will tell me whether or not a particular field is required?  
> Failing that, can I access the complete list of validations so I  
> can look through it for instances of validates\_presence\_of?

Validations cannot be introspected, primarily because they might be  
conditional/procedure dependent. A validation might _exist_ or  
might _not_ exist depending on th state of the record.

–  
Julian ‘Julik’ Tarkhanov  
please send all personal mail to  
me at julik.nl

---

<div class="post-metadata">

**Author:** ![Jon\_Evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jon\_Evans](https://www.ruby-forum.com/u/Jon_Evans)\
**Post date:** [June 5, 2006, 9:49pm UTC](https://www.ruby-forum.com/t/activerecord-validations-and-formbuilder/62483/3 "2006-06-05T21:49:17Z")

</div>

## You might find the code in my plugin helpful … Heck, why not just use the whole thing? 🙂 [http://railsrtv.rubyforge.org/](http://railsrtv.rubyforge.org/)

View this message in context:  
[http://www.nabble.com/ActiveRecord-validations-and-FormBuilder-t1734939.html#a4721023](http://www.nabble.com/ActiveRecord-validations-and-FormBuilder-t1734939.html#a4721023)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Jon\_Evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@Jon\_Evans](https://www.ruby-forum.com/u/Jon_Evans)\
**Post date:** [June 5, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/activerecord-validations-and-formbuilder/62483/4 "2006-06-05T23:08:50Z")

</div>

Hi Julian,

On 5 Jun 2006, at 19:11, Julian ‘Julik’ Tarkhanov wrote:

> conditional/procedure dependent. A validation might _exist_ or  
> might _not_ exist depending on th state of the record.

I guessed as much.

I got round the problem by passing some extra parameters to the  
function:

\<% tabular\_form\_for :user, @user,  
:required =\> [:email, :login] do |f| %\>

```
 [...]
 <%= f.text_field :email %>
 <%= f.text_field :login %>
 [...]

```

\<% end %\>

and each field\_helper can see if a required field is being rendered  
by testing @options[:required].include?(field.to\_sym).

Jon
