我编写了一个控制器和模型来从数据库中获取数据。但是当我们运行 rails is:NameError in ProductsController#index in the url 时它会显示错误。我将我的 url 作为 localhost:3000/products。那么它给出的错误是:
NameError in ProductsController#index
uninitialized constant ProductsController::Product.
my controller is:
products_controller.rb
class ProductsController < ApplicationController
# GET /products
# GET /products.json
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @products }
end
end
#render :text => params and return false
# GET /products/PR1
# GET /products/PR1.json
def show
@product = Product.find(params[:prod_id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @product }
end
end
end
model as product.rb
class Product < ActiveRecord::Base
attr_accessible :model_name, :brand_name, :price, :discount, :qty_available
end
我在 routes.rb 中声明为:资源:产品
我设计了 index.html.erb 和 show.html.erb
我不知道错误在哪里......