user1226943
user1226943

Reputation:

No route matches error but rake routes finds it, Rails.application.routes recognises it

Strangely when I include "resources :blogs" to my routes.rb I get the following error for any other path I try to reach:

No route matches {:action=>"show", :controller=>"blogs"}

The only path I don't get this error for is the "/blogs/:id(.:format)" itself.

Rake routes ("show" for "blogs" in line 5):

    blogs GET    /blogs(.:format)          blogs#index
          POST   /blogs(.:format)          blogs#create
 new_blog GET    /blogs/new(.:format)      blogs#new
edit_blog GET    /blogs/:id/edit(.:format) blogs#edit
     blog GET    /blogs/:id(.:format)      blogs#show
          PUT    /blogs/:id(.:format)      blogs#update
          DELETE /blogs/:id(.:format)      blogs#destroy
  root           /                         pages#home
     home        /home(.:format)           pages#home
 products        /products(.:format)       pages#products
 services        /services(.:format)       pages#services
 research        /research(.:format)       pages#research
                 /blog(.:format)           pages#blog
  contact        /contact(.:format)        pages#contact

On the other hand when tried in console there is no such error for "/products" (for instance) which in the browser returns the "No route matches" error:

1.9.3p327 :010 > Rails.application.routes.recognize_path "/products"
=> {:controller=>"pages", :action=>"products"} 
1.9.3p327 :011 > Rails.application.routes.recognize_path "/blogs/1"
=> {:action=>"show", :controller=>"blogs", :id=>"1"}

Any idea?

UPDATE:

Here is my blogs_controller.rb:

class BlogsController < ApplicationController
  def show
    @blog = Blog.find(params[:id])
  end

  def new
  end
end

and my show.html.erb of the blogs:

<%= @blog.title %>, <%= @blog.description %>

So far this is all I have developed to test my Blog model.

Upvotes: 1

Views: 1012

Answers (1)

dimuch
dimuch

Reputation: 12818

Most likely, you have something like

<%= link_to "Blogs", blog_path =>

in layout template. If so, correct it to <%= link_to "Blogs", blogs_path =>

Upvotes: 1

Related Questions