Ruby on Rails Sunday, March 31, 2013

i add curl --silent http://localhost:3000/products/3/who_bought -H
"Accept: application/xml"

show error: <h1>
in ProductsController#who_bought
<pre>undefined method `order&#x27; for #&lt;Product:0xb6196084&gt;</pre>

<p><code>Rails.root: /home/dima/RubyOnRails/Projects/depot</code></p>

its my product.rb:

class Product < ActiveRecord::Base
has_many :line_items, dependent: :destroy
has_many :orders, through: :line_items

before_destroy :ensure_not_referenced_by_any_line_item

attr_accessible :title, :description, :image_url, :price

validates :title, :description, :image_url, :price, :presence => true
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :title, uniqueness: true
# validates :image_url, allow_blank: true, format: {
# with: %r{ \.(gif|jpg|png)$}i,
# message: 'gif, jpg png. '
#validates :image_url, :uniqueness => false

def ensure_not_referenced_by_any_line_item
if line_items.empty?
return true
errors.add(:base, " have products line")
return false


Posted via

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
For more options, visit

No comments:

Post a Comment