Question for method_missing

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?

On 2/3/07, Marcelo J. [email protected] wrote:

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 C.
http://depixelate.com

Yes, this helps…thanks!

But I would like to make using method_missing, therefore he would be
more generic.