# Automatically show "\*" if a field is required

**URL:** <https://www.ruby-forum.com/t/automatically-show-if-a-field-is-required/48075>\
**Category:** Rails\
**Created:** [November 16, 2005, 4:17pm UTC](https://www.ruby-forum.com/t/automatically-show-if-a-field-is-required/48075 "2005-11-16T16:17:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvano.stralla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@silvano.stralla](https://www.ruby-forum.com/u/silvano.stralla)\
**Post date:** [November 16, 2005, 4:17pm UTC](https://www.ruby-forum.com/t/automatically-show-if-a-field-is-required/48075/1 "2005-11-16T16:17:28Z")

</div>

Hello everybody!

Suppose I create a model like the following:

class Email \< ActiveRecord::Base  
validates\_presence\_of :name  
end

Is it possible to know the presence of “validates\_presence\_of” from a  
view?  
I imagine a helper in the view that automatically shows a “\*” if the  
field passed as a parameter is compulsory…

Thanks,  
Silvano

–  
. . . Silvano S. . . .  
e-mail: removed\_email\_address@domain.invalid  
site: [http://www.sistrall.it](http://www.sistrall.it)  
flog: [http://www.sistrall.it/flog](http://www.sistrall.it/flog)

---

<div class="post-metadata">

**Author:** ![silvano.stralla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@silvano.stralla](https://www.ruby-forum.com/u/silvano.stralla)\
**Post date:** [November 16, 2005, 6:30pm UTC](https://www.ruby-forum.com/t/automatically-show-if-a-field-is-required/48075/2 "2005-11-16T18:30:10Z")

</div>

silvano.stralla wrote:

> Hello everybody!
> 
> Suppose I create a model like the following:
> 
> class Email \< ActiveRecord::Base  
> validates\_presence\_of :name  
> end
> 
> Is it possible to know the presence of “validates\_presence\_of” from a  
> view?  
> I imagine a helper in the view that automatically shows a “\*” if the  
> field passed as a parameter is compulsory…
> 
> Thanks,  
> Silvano
> 
> –  
> . . . Silvano S. . . .  
> e-mail: removed\_email\_address@domain.invalid  
> site: [http://www.sistrall.it](http://www.sistrall.it)  
> flog: [http://www.sistrall.it/flog](http://www.sistrall.it/flog)

I assume that you are trying to show the user the input field that has  
been rejected? If so, the scaffold code generated will do this (it puts  
a big box around the rejected field(s)). Generate a dummy project and a  
scaffold and look how they do it there.

Rick

---

<div class="post-metadata">

**Author:** ![silvano.stralla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@silvano.stralla](https://www.ruby-forum.com/u/silvano.stralla)\
**Post date:** [November 16, 2005, 6:36pm UTC](https://www.ruby-forum.com/t/automatically-show-if-a-field-is-required/48075/3 "2005-11-16T18:36:11Z")

</div>

I think he wants to automatically show during the initial display of the  
form which fields will be validated and required.

Thanks,  
Eugene Cook

---

<div class="post-metadata">

**Author:** ![silvano.stralla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@silvano.stralla](https://www.ruby-forum.com/u/silvano.stralla)\
**Post date:** [November 16, 2005, 10:34pm UTC](https://www.ruby-forum.com/t/automatically-show-if-a-field-is-required/48075/4 "2005-11-16T22:34:54Z")

</div>

Rick Williams \<willirl@…\> writes:

> I assume that you are trying to show the user the input field that has  
> been rejected? If so, the scaffold code generated will do this (it puts  
> a big box around the rejected field(s)). Generate a dummy project and a  
> scaffold and look how they do it there.

I can’t use scaffold (because I need more complex form) and I don’t like  
the way  
it shows errors: I want, for example, write error messages beside  
fields.

I want to show if a field is required during the initial display of the  
form:  
more generally, I want have access from the view to the validation  
schema of the  
model. Is it possible?

Thanks,  
Silvano
