On Jueves, 29 de Julio de 2010 12:40:42 Balaji escribió:
> Hi
>
> I have the following scenario
>
> Order belongs to agents
>
> When user logs in as agent and creates an order, the i need to show
> the current user's agent information on top right corner and save it
> when the order gets created
> When user logs is as admin, he should be able to see who created the
> order at the same location
>
> I have set config.columns[:agent]=:select in the order controller. It
> shows as dropdown and i need to set the current user agent information
> as selected when he opens the order screen.
Add a before_create callback in the model. Note you can use current_user
method in your models because ActiveScaffold add some methods to get that info
from model layer, usually you can't access to session data from model layer.
class Order
before_create :set_agent
def set_agent
self.created_by = current_user if current_user and current_user.is_agent?
end
And remove :agent column from create and update forms.
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 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.