I want to implement a custom route helper function for a Post model, which can either link to a thread root, or a thread root with a hash in the case that the Post is a reply to the thread (they share the Post model).
Where can I define this function to make it easily accessible from within controllers, views, and templates?
I've been able to get away with implementing the function as in the PostView, but now I would like to use it from the controller, and it seems like it would be appropriate to live in Router.Helpers like the other URL helpers.
I've tried implementing it in the Router, but that doesn't work as expected either.
def post_path(conn, action, post) do
if Post.thread?(post) do
"#{board_thread_path(conn, action, post.board.path, post)}"
else
"#{board_thread_path(conn, action, post.board.path, post.thread)}#post-#{post.number}"
end
end