Привет, извините, если это глупый вопрос, правда, я новичок в мире ROR и пытаюсь учиться.
Я читаю книгу Agile Web Develpment с Rails и следую книжной программе, которую я получил с этой ошибкой:
NoMethodError в Line itemsController # create
У вас есть нулевой объект, когда вы этого не ожидали!Возможно, вы ожидали экземпляр Array.Произошла ошибка при оценке nil.
Это модель корзины
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
И это контроллер строки, метод которого вызывается
def create
@cart = current_cart
product = Product.find(params[:product_id])
@line_item = @cart.add_product(product.id)
respond_to do |format|
if @line_item.save
format.html { redirect_to(@line_item.cart, :notice => 'Line item was successfully created.') }
format.xml { render :xml => @line_item.cart, :status => :created, :location => @line_item }
else
format.html { render :action => "new" }
format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
end
end
end
Rails версия 3.0.5 Ruby версия 1.8.7
Есть предложения?ты видишь, что не так?Спасибо