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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 27 April 2013 11:40, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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?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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sat, Apr 27, 2013 at 6:40 AM, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 Aronson, the T. Rex of Codosaurus LLC, secret-cleared freelance software developer available for contracts or temp employment. See information at http://www.Codosaur.us/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
> 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 29 April 2013 01:03, Soichi Ishida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> 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> > soichi > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.