0

Hi I'm playing with Rails at the moment and building a basic app. When I try to run the app I get this error:

"undefined method `products_path' for #<#:0x45c19f8>"

My code is as follows...

Config:

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

Controller:

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

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

View:

<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 %>

I don't understand why the form won't render and I receive the error message. Am I missing something?

Thanks any help appreciated.

Edited to add config file.

Kane
  • 914
  • 2
  • 11
  • 27

1 Answers1

1

Just add the following line in config/routes.rb

resources :products
techvineet
  • 5,041
  • 2
  • 30
  • 28
  • I tried using "resources :products" and "resources :product". Neither works. – Kane Aug 20 '13 at 13:47
  • The problem is your controller is not plural it should class ProductsController < ApplicationController – techvineet Aug 20 '13 at 13:50
  • I realised I should have made it plural after I had done it. Can I not name it whatever I like? Is it the case that if the Controller is not named in the plural the app cannot work? – Kane Aug 20 '13 at 13:53
  • Yeah its a rails convention that controller names will always be pluralized. You can name it whatever you like but it should be pluralized. – techvineet Aug 20 '13 at 13:58
  • OK, so how can I make mine work considering that I have named my Controller as a singular rather than plural? – Kane Aug 20 '13 at 13:59
  • Hope this will help http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails – techvineet Aug 20 '13 at 14:03