Я использую: rails 2.3.5 ruby 1.8.7 и Windows 7 Home Basic
Мне дали базу данных, и я подключил ее к rails, не испытывая проблем при чтении и получении данных из нее.Теперь я хочу добавить в него некоторые функции (добавлять, редактировать и удалять), но когда я пытаюсь установить свой первичный ключ на первичный ключ таблицы (ProductCode), выполнив этот код:
class Product < ActiveRecord::Base
self.primary_key :ProductCode
end
Я получил эту ошибку при выполнении @products = Product.find(:all, :limit => 10)
:
ArgumentError в PosController # index неправильное количество аргументов (1 для 0)
Как мне решить эту проблему?
Воткод моего контроллера:
class PosController < ApplicationController
def index
@cards = Card.find(:all)
@products = Product.find(:all, :limit => 10)
end
def new
@pro = Product.new
end
def edit
@pro = Product.find(params[:id])
end
def update
@pro = Product.find(params[:id])
if session[:user_id]
@log = "Welcome Administrator!"
@logout="logout"
else
@log = "Admin Log in"
@logout=""
end
respond_to do |format|
if @pro.update_attributes(params[:product])
flash[:notice] = 'product was successfully updated.'
format.html { redirect_to(:controller => "pos", :action => "index") }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @pro.errors, :status => :unprocessable_entity }
end
end
end
def create
@pro = Product.new(params[:product])
respond_to do |format|
if @pro.save
flash[:notice] = 'product was successfully created.'
format.html {redirect_to (:controller => "pos", :action => "index")}
#format.xml { render :xml => @product, :status => :created, :location => @product }
else
format.html { render :controller => "pos",:action => "new" }
#format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@pro = Product.find(params[:id])
@pro.destroy
respond_to do |format|
flash[:notice] = 'product was successfully deleted.'
format.html { redirect_to(:controller => "pos", :action => "index") }
format.xml { head :ok }
end
end
end