Forum: Ruby on Rails Automatically show "*" if a field is required

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.
silvano.stralla (Guest)
on 2005-11-16 17:17
(Received via mailing list)
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
flog: http://www.sistrall.it/flog
Rick W. (Guest)
on 2005-11-16 19:30
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
> 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
ecook (Guest)
on 2005-11-16 19:36
(Received via mailing list)
I think he wants to automatically show during the initial display of the
form which fields will be validated and required.

Thanks,
Eugene Cook
silvano.stralla (Guest)
on 2005-11-16 23:34
(Received via mailing list)
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
This topic is locked and can not be replied to.