Been a while since last time I worked with Rails so is taking me a
while get back to full speed.
For a specific scenario I’m facing right now, I required to implement
a generic REST controller that accept any kind of resource and provide
a @collection or @record to work with.
I take from the route requirements the name of the resource
(params[‘resource_name’]) and then constantize it.
Since I keep doing that for several actions, I found cumbersome and
cryptic have this in my actions:
@collection = params[‘resource_name’].camelize.constantize.find(…)
You get the idea: something very ugly and something that will break if
I don’t be careful enough.
So I tried to extract it to it’s own method (resource_class), but
wrapping my brain to spec it is taking me a while.
At this point, I don’t like the feeling that resource_class is being
stubbed or expected in some actions, but not actually executed.
This is the pastie:
Do you guys think that will be best to put the resource_class stub
inside the actions and create another context to deal with those
Thanks in advance for your suggestions.
Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.