Automatically show "*" if a field is required


#1

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


#2

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


#3

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

Thanks,
Eugene Cook


#4

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