質問

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!

役に立ちましたか?

解決

Add to helper code:

def upvote_path(model)
  "/votes/#{self.class.name.downcase}_#{self.id}/upvote"
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top