rubyonrailsin

A Ruby and Rails talk

Sunday, March 14, 2010


[Rails] determining where a function is called from

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

I have a function that I use in my code in a number of places. It does
some database lookup, processes it and returns some content to display.
However, it needs to know where it was called from so that it can set up
some return links. Currently I call it from a controller like this:

@content = Content.getContent( "Hello from ", controller_name(),
action_name() )

I want to dry up the code and get rid of the controller and action calls
and move it to the model where it belongs, but the controller_name and
action_name functions are not available in the model.

My question, is there any way for the code in the model to discover
where the function was called from so that that information can be made
available to the function without having to explicitly pass it.

Hope someone can help,
-- Will

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive