In my Article model (rails 3), I want to create methods that takes a parameter.
So开发者_StackOverflow社区 I can do things like:
Article.get_by_id(:cache => true, :cache_expire => some_date)
I want to re-use this parameter, how can I do this?
The parameter is a hash of options, and I want to use it in many of my controllers methods.
you can add following method to Article model
self.get_by_id(options = {})
cache = options['cache']
end
Now the parameter sent to the above method can be accessed using option hash. i.e, options['cache'] and options['cache_expired'].
Do you mean like this?
custom_options = { :cache => true, :cache_expire => some_date }
Article.get_by_id(custom_options)
I'm sorry if I am not getting you but your question was very brief.
精彩评论