Required field for one, optional for another

rails 3.2.11

My app has User model, its one of the fields is entrepreneur:boolean.

So users have two types; one is normal users, the other is professional
users.

For normal users, only emails and usernames are required and other
fields are optional.
For professional users, in addition to above, addresses and real names
are required.

Is there any Ruby way to set the requirement depending on the type of
users?

Is JavaScript the only way?

Sorry about to being too broad and too general. To be honest, I have no
idea where to start.

Soichi

On 27 April 2013 11:40, Soichi I. [email protected] wrote:

are required.

Is there any Ruby way to set the requirement depending on the type of
users?

Are you talking about making the display change automatically
immediately the user selects which sort of user he is? If so then
probably javascript is the right way to do it. You could use ajax but
that would require a request to the server so probably not a good
plan.

Colin

On Sat, Apr 27, 2013 at 6:40 AM, Soichi I. [email protected]
wrote:

Is there any Ruby way to set the requirement depending on the type of
users?

If I recall correctly, some of the standard validation helpers will
take an “if” parameter, such that if the parameter evaluates to false,
the validation is not applied. If worst comes to worst, you can
validate with a method you write yourself, that looks at that flag and
Does The Right Thing depending on whether it’s set.

-Dave


Dave A., the T. Rex of Codosaurus LLC,
secret-cleared freelance software developer
available for contracts or temp employment.
See information at http://www.Codosaur.us/.

Are you talking about making the display change automatically
immediately the user selects which sort of user he is?

Not really.
I was thinking that when users sign up, they are either one type or the
other. So, the required fields need to be set accordingly. User model
validations hopefully filter upon submitting.

If I recall correctly, some of the standard validation helpers will
take an “if” parameter, such that if the parameter evaluates to false,

Seems great. I will search for it.

soichi

On 29 April 2013 01:03, Soichi I. [email protected] wrote:

take an “if” parameter, such that if the parameter evaluates to false,

Seems great. I will search for it.

Have a look at the Rails Guide on ActiveRecord Validations and
Callbacks. Also check out the other guides.

Colin