Person#no中的NoMethodError

时间:2014-03-20 21:54:21

标签: ruby-on-rails ruby

#<#:0x007f4be4bfbaa8>的未定义方法`people_path' 提取的来源(第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%>

----人物控制器----

  def new
    @people = Person.new
  end

我打电话给人/新

时出错

---- -----航线
  得到“人/新”
  得到“人/指数”
  得到“人/秀”   得到“人/删除”
  得到“人/更新”
  得到“人/创造”

资源:人

---- ----迁移
class CreatePeople&lt; ActiveRecord的::迁移
  def change     create_table:人们做| t |
        t.string:first_name
        t.string:last_name
        t.string:company
        t.string:email
        t.string:phone
      t.timestamps
    结束
  结束
结束

- 型号 -
class Person&lt;的ActiveRecord :: Base的
结束

2 个答案:

答案 0 :(得分:0)

routes.rb中,您的路线应定义如下:

resources :people

这种方式people_path可用。 在此之后,您可以运行rake routes并检查为您创建的路线,如下所示:

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

答案 1 :(得分:0)

尝试替换它:

<% form_for (@people) do |f|%> 

为此:

<% form_for url_for(controller: 'person', action: 'create', id: @people) do |f|%>