我正在關注article以測試站點地圖生成。該文章沒有提及任何關於編寫show
的行動。但是,自從我開始得到這個錯誤,我甚至寫了一個簡單的show
操作。以下是我的帖子控制器:沒有路線匹配{:action =>「show」....:controller =「posts」}
def index
@posts= Post.all
end
def show
@posts = Post.all
end
的routes.rb
Rails.application.routes.draw do
resources :categories do
resources :posts
end
root to: 'pages#index'
end
sitemap.rb
Category.find_each do |category|
add category_posts_path(category), :changefreq => 'weekly', :lastmod => category.updated_at
category.posts.each do |post|
add category_post_path(category), :changefreq => 'yearly', :lastmod => post.updated_at
end
end
當我運行rake sitemap:refresh
,它給以下:
In '/home/mypc/Projects/sitemaptest/public/':
rake aborted!
ActionController::UrlGenerationError: No route matches {:action=>"show", :category_id=>#<Category id: 1, title: "Surprised by Joy", created_at: "2017-04-07 09:13:52", updated_at: "2017-04-07 09:13:52">, :controller=>"posts"} missing required keys: [:id]