2013-08-20 52 views
0

嗨我現在正在玩Rails並構建一個基本的應用程序。當我嘗試運行應用程序,我得到這個錯誤:在Rails 3.2中沒有方法錯誤

「未定義的方法`products_path」爲#<#:0x45c19f8>」

我的代碼如下......

配置:

Depot::Application.routes.draw do 
    resources :product 
    resources :test 
end 

控制器:

class ProductController < ApplicationController 
    def new 
    @product = Product.new 
    end 

    def show 
    @product = Product.find(params[:id]) 
    end 
end 

查看:

<h1>Page to add new products</h1> 

<%= form_for(@product) do |f| %> 
    <%= f.label :title %> 
    <%= f.text_field :title %> 

    <%= f.label :description %> 
    <%= f.text_field :description %> 

    <%= f.label :price %> 
    <%= f.text_field :price %> 

    <%= f.submit "Create new product" %> 
<% end %> 

我不明白爲什麼表單不會呈現並且收到錯誤消息。我錯過了什麼嗎?

謝謝任何​​幫助表示讚賞。

編輯添加配置文件。

+0

顯示你的config/routes.rb文件 –

回答

1

只需添加下面一行到config/routes.rb中

resources :products 
+0

我嘗試使用 「資源:產品」 和 「資源:產品」。兩者都不起作用。 – Kane

+0

問題是你的控制器不是複數,它應該類ProductsController techvineet

+0

我意識到我應該已經完成​​它後,它已經複數。我可以不說出任何我喜歡的名字嗎?如果Controller沒有以複數名稱命名,那麼應用程序無法工作? – Kane