Ruby on rails Rails嵌套路由到html id

Ruby on rails Rails嵌套路由到html id,ruby-on-rails,routing,nested-resources,Ruby On Rails,Routing,Nested Resources,给定一个博客风格的应用程序: #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 我不认为路由会为锚点生成这样的方法,但您可以将锚点添加到

给定一个博客风格的应用程序:

#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

我不认为路由会为锚点生成这样的方法,但您可以将锚点添加到帖子的url生成器中

 post_path(@post, :anchor => "comments")
 post_path(@post, :anchor => "comment#{@comment_id}")

我处理这个问题的方法是生成commentshow操作的路径,然后通过erikpost方法重定向到锚

 post_path(@post, :anchor => "comments")
 post_path(@post, :anchor => "comment#{@comment_id}")