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)

And place this in application.rb.

How make this?

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

How make this?


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:


def current_usuario
@current_usuario ||= (session[:usuario_id] ?
Usuario.find(session[:usuario_id]) : nil)
helper_method :current_usuario

Hope this helps.

Zack C.

Yes, this helps…thanks!

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