Cristian Hoyos
Cristian Hoyos

Reputation: 1255

undefined method `people_path' for #<#<Class:0x007f4bcc6bbbf0>:0x000000023b70c0>

undefined method `people_path' for #<#:0x000000023b70c0> Extracted source (around line #4):

Person#new

Find me in app/views/person/new.html.erb

<% form_for (@person) do |f|%>
<%= f.label :first_name%>
<%= f.text_field :first_name%>
<%= f.label :last_name%>

controller-->

def new
@person = Person.new
end

routes-->

get "person/new"
get "person/index"
get "person/show"
get "person/delete"
get "person/update"
get "person/create"

resources :person

Upvotes: 0

Views: 1556

Answers (3)

Daniel Rikowski
Daniel Rikowski

Reputation: 72514

According to the Rails conventions your controller names must be plural versions of your model names.

For example:

  • User / UsersController
  • Message / MessagesController
  • Contact / ContactsController
  • ...

And because the plural of "person" is "people":

  • Person / PeopleController

This convention is true even for singleton resources!

There are ways to override these conventions, but they are a hassle and take away much from the elegance of Rails routing. In general overriding conventions in Rails often produces "ripple effects" which force you to manually do stuff at other places, too.

In a nutshell: Make your life easy and use the following names:

  • Model: Person
  • Controller: PeopleController
  • Route: resources :people

Upvotes: 3

Richard Peck
Richard Peck

Reputation: 76774

Your problem is here:

#config/routes.rb
get "person/new"
get "person/index"
get "person/show"
get "person/delete"
get "person/update"
get "person/create"

resources :person

According to the Rails Routing documentation, your setting of the routes manually is not in line with convention (RESTful routes). You're best using resources :controller only:

#config/routes.rb
resources :person

This is taking into consideration that your controller is called persons_controller.rb (as you stated in your comments)

Upvotes: 0

vee
vee

Reputation: 38645

Given your controller is PeopleController, update your route file as follows:

# config/routes.rb

# Use plural, i.e. people not person
resources :people 

Upvotes: 1

Related Questions