kalpetros
kalpetros

Reputation: 983

NoMethodError with Ruby app

The user is presented with a contact page where he can add a new contact by clicking the create button (Then the app takes him in a new page to add the contact's title)

<%= link_to "Create", new_contact_path  %>

When I click create I get the following error:

undefined method `contacts_path' for #<#<Class:0xsomeHEX>:0xsomeHEX>

The above error disappears when I create the controller like this:

rails generate controller contacts

Also the routes.rb file points to:

resources :contact

Below are my files:

  1. contact_controller.rb
  2. contact_helper.rb
  3. _form.html.erb

What I want to achieve is to go to the new contacts page by typing someurl/contact/new instead of /contacts/new

Upvotes: 0

Views: 41

Answers (3)

DustinFisher
DustinFisher

Reputation: 396

In your config/routes.rb change your contacts route to this:

  resources :contacts, path: "contact"

That gives you the ability to hit your routes using 'contact' instead of 'contacts'.

Upvotes: 2

Prashant4224
Prashant4224

Reputation: 1601

Please make these changes

contacts_controller.rb

class ContactsController < ApplicationController
  ....
end

routes.rb

resources :contacts

Your views folder should be views/contacts

Upvotes: 0

sts
sts

Reputation: 380

rename routes to resources :contacts

Upvotes: 1

Related Questions