Reputation: 505
given a blog style application:
#models
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
#routes.rb
map.resources :posts do |posts|
posts.resources :comments
end
how do I generate routes to an id on a page? Examples
/posts/1#comments
/posts/2#comment14
Upvotes: 0
Views: 228
Reputation: 598
The way I handled this was to generate the path to the comment show action which then redirected to the anchor via the method erik posted.
Upvotes: 0
Reputation: 6436
I don't think the routes generate methods for anchors like that, but you can add anchors into the url generators for posts.
post_path(@post, :anchor => "comments")
post_path(@post, :anchor => "comment#{@comment_id}")
Upvotes: 2