Reputation: 5880
I have two routes:
/votes/:id/upvote
/votes/:id/downvote
the votes
controller is going to handle different votable
models.
What I'd like to do is make upvote_path(@model)
to become /votes/"model_class"_"model_id"/upvote
this could be done by overriding to_param
in a specific model like so:
def to_param
"#{self.class.name.downcase}_#{self.id}"
end
but this would mean I'd have to do that for all votable
models, plus I don't want other routes to be affected. Any ideas? Thanks!
Upvotes: 1
Views: 380
Reputation: 23556
Add to helper code:
def upvote_path(model)
"/votes/#{self.class.name.downcase}_#{self.id}/upvote"
end
Upvotes: 1