On Miércoles, 3 de Junio de 2009 21:05:13 Carl Anderson escribió:
> I wonder (and I could be wrong here) if you could do something like this:
>
> def create
>    if <someconditions>
>       @record.sms_id = whatever
>       @record.role_id = 1
>    else
>        @record.cis_id = whatever
>        @record.role_id = 2
>     end
>     do_create #I think this is where the normal create action occurs and
> validations would get checked
>     respond_to_action(:create)
>   end
>
> I'm very unsure if this would work, but based upon what was suggested (and
> worked) for a similar question I had about the new action, I think it (or
> some variation) might work for you.

It doesn't work, @record doesn't exist before do_create
It should put the code in before_create_save, which is called before 
validations.

>
> On Wed, Jun 3, 2009 at 11:57 AM, G. Sobrinho 
<[email protected]>wrote:
> > Hello,
> >
> > I have this situation:
> >
> > 1. User which have cis_id, sms_id, provider_id and role_id
> > 2. Sms, Cis and Provider which have many Users associated
> >
> > I setted associations on models and now i need to set the sms_id, cis_id
> > or provider_id on user when I create one of those models. That's works by
> > default on AS, but I need to set role_id also for each situation.
> > Example:
> >
> > When I create new Sms with 3 users associated, then set sms_id (default)
> > and set role_id to 1
> > When I create new Cis with 2 users associated, then set cis_id and set
> > role_id to 2
> >
> > I tryed to use before_create/update_save but the user validation fails on
> > user because that is called after validation and I don't setted the
> > role_id (user model validate that). Suggestions?
> >
> >
> > Thank you
> >
> > --
> > Regards,
> >
> > Gabriel Sobrinho
> > +55 31 8775 8378
>
> 
-- 
Sergio Cambra .:: entreCables S.L. ::.
Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to