Rails帮助简单形式:Konkurrancers#new中的NoMethodError

时间:2011-03-02 12:42:35

标签: ruby-on-rails ruby-on-rails-3

我有一个简单形式的问题,我得到这个错误网址(http:// localhost:3000 / konkurrencer / new): 显示C:/Rails/konkurranceportalen/app/views/konkurrancers/_form.html.erb第1行提出:

undefined method `konkurrancers_path' for #<#<Class:0x382ea08>:0x382d4a8>

Extracted source (around line #1):

1: <%= simple_form_for(@konkurrancer) do |f| %>
2:     <%= f.error_messages %>
3:     <%= f.input :name %>
4:     <%= f.input :banner1 %>

我的模特konkurrancer.rb

class Konkurrancer < ActiveRecord::Base
has_many :ratings
belongs_to :kategori
validates_presence_of :name, :tracking, :banner1, :banner2, :kategori_id, :udtraekkes, :arrangeor
has_friendly_id :name, :use_slug => true
end

我的表格:

<%= simple_form_for(@konkurrancer) do |f| %>
    <%= f.error_messages %>
    <%= f.input :name %>
    <%= f.input :banner1 %>
    <%= f.input :banner2 %>
    <%= f.input :tracking %>
    <%= f.input :arrangeor %>
    <%= f.input :vaerdi %>
    <%= f.input :udtraekkes %>
    <%= f.association :kategori %>
    <%= f.input :note %>
    <%= f.button :submit %>
<% end %>

我的控制器:

  def new
    @konkurrancer = Konkurrancer.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @konkurrancer }
    end
  end

我的路线.rb

resources :konkurrencer, :controller => 'konkurrancers'

1 个答案:

答案 0 :(得分:1)

您可能没有将koncurrancer定义为config/routes.rb中的资源。只有将其定义为资源时,才会定义koncurrancers_path辅助方法。你应该添加

map.resources :koncurrancers

到您的routes.rb文件