Colin Law wrote in post #1155829:
> You have a variable called @line_item and are trying to reference the
> member @line_item.expensescounter.  I assume that @line_item is an
> object of class LineItem.  Is that correct?

 Yes, it is correct.

> Assuming the above is correct then what is LineItem.expensescounter?
> Is it an association, so in the lineitem class you have lineitem
> belongs_to Expensescounter or has_one Expensescounter?  If so then at
> some point you should have made an expensescounter and assigned it to
> a lineitem object and saved them both in the database.  Your error
> suggests that the lineitem object in @line_item does not have an
> associated expensescounter.  So the code you need to show is how you
> create the expensescounter and then give it to the lineitem.  All you
> have showed so far is a public method (current_expensescounter) which
> finds or creates one, but there is nothing to say that it belongs to
> the particular lineitem referenced by @lineitem.

I have created relationship between line items, expensescounter and 
quantity.

It is an association between lineitem and expensescounter. I am 
providing code of model:

> Code of cart.rb:

class Expensescounter < ActiveRecord::Base
  attr_accessible :user_id

  has_many :line_items, dependent: :destroy
  belongs_to :user

  validates :user_id, presence: true
  default_scope order: 'expensescounters.created_at DESC'
.
.
.
end

> code of line_item.rb:

class LineItem < ActiveRecord::Base
   attr_accessible :quantity_id, :expensescounter_id

  belongs_to :quantity
  belongs_to :expensescounter
.
.
.
end

> code of quantity.rb:

class Quantity < ActiveRecord::Base
.
.
  has_many :line_items

  before_destroy :ensure_not_referenced_by_any_line_item
.
.
.
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 rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/c9320b752e0d8e02197c27ea4da1c900%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to