Question has many Comments.
A URL "questions/123" shows a question.
A URL:
"questions/123#answer-345"
shows a question and highlights an answer. 345 - is id of Answer model, "answer-345" is id attribute of HTML element.
I need to override "answer_path(a)" method to get
"questions/123#answer-345"
instead of
"answers/345"
How to do it ?
All url and path helper methods accept optional arguments.
What you're looking for is the anchor
argument:
question_path(123, :anchor => "answer-345")
It's documented in the URLHelper#link_to examples.
Using this argument, you should be able to create an answer_path
helper via:
module ApplicationHelper
def answer_path(answer)
question_path(answer.question, :anchor => "answer-#{answer.id}")
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With