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

show error: <h1>
  NoMethodError
    in ProductsController#who_bought
</h1>
<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
    else
      errors.add(:base, " have products line")
      return false
    end
  end

end

-- 
Posted via http://www.ruby-forum.com/.

-- 
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 [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to