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

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

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

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

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.

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

Colin