ruby on rails - No route matches {:action=>"show".... :controller = " posts" } -


i following article test sitemap generation. article didn't mention writing show action. since started error, wrote simple show action. following posts controller:

def index   @posts= post.all end  def show  @posts = post.all end 

routes.rb

rails.application.routes.draw     resources :categories       resources :posts     end     root to: 'pages#index' end 

sitemap.rb

 category.find_each |category|     add category_posts_path(category), :changefreq => 'weekly', :lastmod => category.updated_at      category.posts.each |post|       add category_post_path(category), :changefreq => 'yearly', :lastmod => post.updated_at     end   end 

and when run rake sitemap:refresh , it's giving following:

in '/home/mypc/projects/sitemaptest/public/': rake aborted! actioncontroller::urlgenerationerror: no route matches {:action=>"show", :category_id=>#<category id: 1, title: "surprised joy", created_at: "2017-04-07 09:13:52", updated_at: "2017-04-07 09:13:52">, :controller=>"posts"} missing required keys: [:id] 

i think missed post param at:

category.posts.each |post|   add category_post_path(category), :changefreq => 'yearly', :lastmod => post.updated_at end 

its should be:

 category.posts.each |post|    add category_post_path(category, post), :changefreq => 'yearly', :lastmod => post.updated_at  end 

hope helps.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -