Sorry, sorry, sorry... I writted my code wrong, before_create/update_save
works:

class CisController < ApplicationController
  # ....
  def before_update_save record
    record.users.each do |user|
      user.role_id = Role::CIS_ADMIN_ID
    end
  end
end

I writted before_update and tested on create, that works... Sorry for my
error...


Thank you Carl

2009/6/3 Carl Anderson <[email protected]>

> 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.
>
>
> 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
>>
>>
>>
>
> >
>


-- 
Atenciosamente,

Gabriel Sobrinho
+55 31 8775 8378

--~--~---------~--~----~------------~-------~--~----~
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