Undefined method 'controllerName_path', did you mean 'controllerName_new_path'

I am super new to learning Rails. Please forgive me if this is a repeated question. So, I am trying to create a simple docs application. So far I have created a controller, views and a model for it. _forms.html.haml (partial view used to render form on docs/new page): dogbin - ymegevystu

new.html.haml (this is where I am rendering form partial): dogbin - rifinamuno

docs_controller.rb (controller for docs): dogbin - thestugyne

Error I am facing when going to localhost/docs/new: dogbin - grangatime

Please help if possible

This usually happens when the resources in your routes are named singular instead of plural.

One of rails’ most important conventions is the following:

Model names should be singular: models/doc.rb Controller names should be plural: controllers/docs_controller.rb

Could you show us the contents of your routes.rb file?

When you build a form rails can make a ton of assumptions for you that may seem as magic at first but are quite simple.

You’re building a form for a new @doc. Rails knows that this doc hasn’t been created so it adds a route to the create action automatically for you (look at the html rendered in the browser using the browser’s dev tools) using a route helper. What this error is telling you is that it cannot find this helper which is defined by your route file.

Open localhost:3000/rails/info/routes to see all the routes defined in your app with their corresponding helpers. That should give you a clue to fix the error

Hi, Julian. Thanks for the reply, and sorry for late reply; got caught up in work. I am aware of the naming convention, and I have followed it. routes.rb file: dogbin - zullemocyf You say localhost:3000/docs/new hasn’t been created, but this is what new function in docs_controller.rb is supposed to do (so far, at least) - create a new instance of doc. It seems like form partial view is not able to find the doc instance which should be created when user goes to localhost/docs/new. I still am not able to figure out what I did wrong. Please help me some more if you can. I am attaching a screenshot of localhost:3000/rails/info/routes. Thank you once again.

The problem lies in your routes as I suggested.

Rails has also very strong conventions with routing. Follow this section of the rails guide on routing.

In short, what you need to do is define your routes using the”resources” method. In your case resources :docs This will create the 7 RESTful actions with the exact route addresses, names and helpers rails needs for it to work its magic.

Let me know how that goes

And also, be careful to follow the HTTP conventions for get/put/patch/delete. I just saw all your routes were “get” which isn’t correct. Using resources Will help you learn and enforce those conventions

Isn’t running “rails generate controller” command supposed to create route with a get request? I think that’s what created all those routes with get request for me.

It finally worked. I get it now. Thank you so much.