Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

<h1>Person#new</h1>
<p>Find me in app/views/person/new.html.erb</p> 

<% form_for (@people) do |f|%>
<%= f.label :first_name%>
<%= f.text_field :first_name%>
<%= f.label :last_name%>
<%= f.text_field :last_name%>
<%= f.label :company%>
<%= f.text_field :company%>
<%= f.label :email%>
<%= f.text_field :email%>
<%= f.label :phone%>
<%= f.text_field :phone%>
<%end%>

---- Person Controller ----

  def new
    @people = Person.new
  end

I have an error when I call person/new

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

resources :person

----migrate----
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :first_name
t.string :last_name
t.string :company
t.string :email
t.string :phone
t.timestamps
end
end
end

--model--
class Person < ActiveRecord::Base
end

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
624 views
Welcome To Ask or Share your Answers For Others

1 Answer

In routes.rb, your routes should be defined as below:

resources :people

This way people_path would be available. After this, you can run rake routes and check the routes created for you as below:

people      GET    /people(.:format)                     people#index
            POST   /people(.:format)                            people#create
new_person  GET    /people/new(.:format)             people#new
edit_person GET    /people/:id/edit(.:format)       people#edit
person      GET    /people/:id(.:format)                 people#show
            PATCH  /people/:id(.:format)                        people#update
            PUT    /people/:id(.:format)                        people#update
            DELETE /people/:id(.:format)                        people#destroy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...