0

I am trying to create a small rails blog, and have run into an error. I think I've messed up the naming convention of something here... but I can't find anything specific enough to help me and give me the answer.

I have a route of

resources :blog

and a controller which has the following

class BlogController < ApplicationController

  def index
    @blogs = Blog.all
  end

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

  def new
    @blog = Blog.new
  end

end

When I try to set up a form on the new.html.erb page, it links to routing which states

undefined method `blogs_path'

My route is blog, not blogs... where am I going wrong? I would like the route to be /blog.

1
  • I'd recommend saying resources :blogs as resources are usually in plural form. Commented Apr 4, 2017 at 12:35

3 Answers 3

1

Following the conventions, rename your controller file to blogs_controller.rb and the class inside of it to BlogsController. Then, in your routes.rb: resources :blogs. It should all work fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help. I went back and set up the blog using the standard naming convention.
1

As already said, it should be :

resources :blogs

And I think the controller should use the plural too : BlogsController

Comments

1

To find what's wrong with urls you can use rake routes command

Values in first column Prefix are names of helpers you can use as prefix_url or prefix_path

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.