I have an issue here where I'm trying to call a class method on an object that is not known... err, I'm not sure how to phrase this I'm getting the :resource from the URL, but I want to run find on it for a differnt param as well.
How can I do something like:
params[:resource].classify.find(params[:id])
I mean this won't work because the params[:resource].classify
would be a string. But how can I run a method on it as if it was a Class
and not a string?
The following used to work fine but the gem friendly_id
has made all my calls to a record to return it's friendly_id and not its actual primary key... which totally sucks.
It was doing something like this, which worked just fine:
@vote = Vote.new({
:vote => params[:direction] == 'up' ? true : false,
:voteable_type => params[:resource].classify,
:voteable_id => params[:id])
})
But since adding friendly_id
my paths now look something like:
/things/my-thing-name/vote/up
instead of the old way:
/things/328/vote/up
So now the params[:id]
is no longer the foreign key.
Thoughts?