Well, I want to make a method that return a model through a session. For example. When I call "obj = session_object_Usuario", return a model Usuario, through session "usuario_id". I think about something as: def method_missing("session_object_"model) model.find(session[":#{model}_id"]) end And place this in application.rb. How make this? -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/3/07, Marcelo Junior <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Well, I want to make a method that return a model through a session. For > example. When I call "obj = session_object_Usuario", return a model > Usuario, through session "usuario_id". I think about something as: > > def method_missing("session_object_"model) > model.find(session[":#{model}_id"]) > end > > And place this in application.rb. > > How make this?Marcelo, I''m trying to figure out why you''d want to use method_missing to load an object from the session... If you''re already typing: obj = session_object_Usuario Then it seems easier, faster, and more secure to define an accessor: # application.rb def current_usuario @current_usuario ||= (session[:usuario_id] ? Usuario.find(session[:usuario_id]) : nil) end helper_method :current_usuario Hope this helps. -- Zack Chandler http://depixelate.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes, this helps....thanks! But I would like to make using method_missing, therefore he would be more generic. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---