Displaying nested association in view in Rails 4 -


i have 3 models below:

class kick < activerecord::base  has_many :offs  has_many :retailers, :through => :off end  class retailer < activerecord::base  has_many :offs  has_many :kicks, :through => :off end  class off < activerecord::base  belongs_to :kicks  belongs_to :retailers end 

and i'm trying display name of retailer in 'show kick view' below:

  <% @kick.off.each do|off| %>     <%= off.name %>     <%= off.retailers.name %>   <% end %> 

off.name displays fine cannot seem index retailer's name view. missing?

error:

undefined method `name' nil:nilclass 

class kick < activerecord::base  has_many :offs  has_many :retailers, :through => :offs end  class retailer < activerecord::base  has_many :offs  has_many :kicks, :through => :offs end  class off < activerecord::base  belongs_to :kick  belongs_to :retailer end 

also make sure indexed models in db


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -