1
<h2>New Product</h2>

<%= form_for @product do|f| %>
    <%= f.label :product_title %><br>
    <%= f.text_field :product_title %><br>
    <br>
    <%= f.label :key_features %><br>
    <%= f.text_area key_features %><br>
    <br>
    <%= f.label :price %>
    <%= f.number_field :price %><br>
    <br>
    <%= f.label :colour %>
    <%= f.number_field :colour %><br>
    <br>
    <%= f.label :main_material %>
    <%= f.number_field :main_material %><br>
    <br>
    <%= f.submit %>
<% end %>


class ProductsController < ApplicationController
    def home
    @product = Product.all
    end
    def new
    @product = Product.new
    end
end

class CreateProducts < ActiveRecord::Migration
    def change
        create_table :products do |t|
            t.string :product_title
            t.text   :key_features
            t.integer :price
            t.string :colour
            t.string :main_material

            t.timestamps null: false
        end
    end
end

Why i'm facing that error?

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
Wasey Raza
  • 230
  • 5
  • 16

3 Answers3

2

I suppose you are getting this error because your app name will also be Product. By default your app name will be a reserved keyword and you cannot use it for naming. If this is the case, you should rename the app to something like product_app to use model name as Product. To rename the app you can refer Renaming a Rails 4 app or How to rename a rails 5 application?. Hope this help.

Muhammed Anees
  • 1,810
  • 1
  • 16
  • 17
0

You need to force to require model product.rb because not auto loading this file on controller like

require 'product.rb'

Very good explanation on @shingara answer

fool-dev
  • 7,671
  • 9
  • 40
  • 54
0

I think you dont have the model class :

file app/model/product.rb

class Product < ApplicationModel
end