укажите весь код cart.rb, если это возможно. Возможно, ваш метод add_product относится к какому-то частному методу, например. Я знаю, что это должен быть комментарий, я хочу объяснить это на примере, поэтому я вставляю его в ответ.
private
def self.some_method
#some code
end
def add_product(product_id)
ваш код из комментария выглядит следующим образом
class Cart < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
end #this end is creating problem
def add_product(product_id)
current_item = line_items.where(:product_id => product_id).first
if current_item
current_item.quantity += 1
else
current_item = LineItem.new(:product_id=>product_id)
line_items << current_item
end
current_item
end
Вы добавляете свой метод после закрытия класса. поставить конец класса после окончания метода, и я уверен, что это сработает.
изменить cart.rb на
class Cart < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
def add_product(product_id)
current_item = line_items.where(:product_id => product_id).first
if current_item
current_item.quantity += 1
else
current_item = LineItem.new(:product_id=>product_id)
line_items << current_item
end
current_item
end
end #this end should after the end of class method