我的rails应用程序中的简单错误

时间:2012-10-29 21:34:44

标签: ruby ruby-on-rails-3

我的rails应用程序中有一个错误,告诉我索引方法未定义。 我创建了一个这样简单的表单,仅用于使用(新方法页面)插入数据 但由于某种原因它现在不起作用

class PeoplesController < ApplicationController

  def index

  end

  def new
    @people = People.new
  end

  def create
    @people = People.new(params[:@people])
    if @people.save
      redirect_to new_people_path
    end
  end
end


# new.html.haml
<h2>Hello there!</h2>
<hr >
<%= form_for @people do |f| %>
    FirstName:<%= f.text_field :first %><br />
    LastName:<%= f.text_field :last %><br />
    <%= f.submit %>
<% end %>

以下是错误代码:

    NoMethodError in Peoples#new

Showing /Users/kasim/Desktop/form/app/views/peoples/new.html.erb where line #3 raised:

undefined method `people_index_path' for #<#<Class:0x007fa33da58d58>:0x007fa34031c578>
Extracted source (around line #3):

1: <h2>Hello there!</h2>
2: <hr >
3: <%= form_for @people do |f| %>
4:  FirstName:<%= f.text_field :first %><br />
5:  LastName:<%= f.text_field :last %><br />
6:  <%= f.submit %>

1 个答案:

答案 0 :(得分:0)

form_for的文档说form_for调用等同于此

<%= form_for @post, :as => :post, :url => post_path(@post), :method => :put, :html => { :class => "edit_post", :id => "edit_post_45" } do |f| %>
  ...
<% end %>

请注意,url属性正在调用命名路由。在您的情况下,命名路由似乎是people_index_path。我会运行rake路由并确保所讨论的命名路由确实存在。