Rails 4.0.2 form_for帮助程序使用错误的路由?

时间:2014-01-02 19:27:54

标签: ruby ruby-on-rails-4 haml

您好我正在尝试使用Rails form_for帮助程序来创建新表单。我已经为表单提供了一个新模型,但是它一直试图使用错误的路由来引发异常的动作attr。当我明确定义动作ex (url: {action: 'create'})

时,它确实有效
class Person < ActiveRecord::Base
end

class PeopleController < ApplicationController
    def new
        @person = Person.new
    end
end

这是在我的配置/路由文件中:

resources :people

这就是我在视图中所做的事情(即使用HAML)

= form_for(@person) do |f|
    = f.label :name
    = f.text_field :name
    = f.submit

,抛出的异常是

  

未定义的方法`people_index_path'

之前我曾经使用它(使用erb和早期版本的rails),所以我不确定它们是怎么回事。非常感谢任何帮助!

Rake路线看起来像这样:

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

这是服务器日志中的报告

Started GET "/people/new" for 127.0.0.1 at 2014-01-02 15:42:06 -0500
Processing by PeopleController#new as HTML
  Rendered people/new.html.haml within layouts/application (61.3ms)
Completed 500 Internal Server Error in 152ms

ActionView::Template::Error (undefined method `people_index_path' for #<#       <Class:0x007ff8bbcf1c08>:0x007ff8bbcf0f10>):
2:  .col-sm-12
3:      %h2 New Person
4:      %p= link_to '< Back', people_path
5:      = form_for(@person) do |f|
6:          =f.label :name
7:          =f.text_field :name
8:          =f.submit

app/views/people/new.html.haml:5:in `_app_views_people_new_html_haml___3574118090840992964_70353159622800'


  Rendered /Users/Graham/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.5ms)
  Rendered /Users/Graham/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.2ms)
  Rendered /Users/Graham/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (28.8ms)

0 个答案:

没有答案