ruby on rails - NoMethodError? Counting Records -


i have following models:

class label < activerecord::base   has_many :releases end  class release < activerecord::base   belongs_to :label   has_many :products   has_and_belongs_to_many :tracks    def self.releases_count    self.count(:all)   end end  class product < activerecord::base   belongs_to :release    has_many :releases_tracks, :through => :release, :source => :tracks         has_and_belongs_to_many :tracks    def self.products_count    self.count(:all)   end  end 

on label/index view i'm able display count of releases absolutely fine using:

 <%= label.releases.releases_count %> 

i'm trying same products using:

 <%= label.releases.products.products_count %> 

but nomethoderror:

 undefined method `products' #<label:0x10ff59690> 

any ideas?

i have lots of other aggregations want perform (track counts etc) guidance on i'm going wrong appreciated.

you need define production/label association

class label < activerecord::base   has_many :releases   has_many :products, :through => :releases end 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -