Below is my index.html.erb (I just want to show a list of Brands and associated Subbrands)
<h1>Brands</h1>
<% @brands.each do |brand| %>
<h2><%= brand.name %></h2>
<% end %>
<% @brands.subbrands.each do |subbrand| %>
<h2><%= subbrand.name %></h2>
<% end %>
The error I receive when viewing index.html is:
undefined method `subbrands' for #<Array:0x9e408b4>
Here is my brands_controller:
class BrandsController < ApplicationController
def index
@brands = Brand.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @brands }
end
end
end
Here is my routes.rb
Arbitrary::Application.routes.draw do
resources :brands do
resources :subbrands
end
resources :subbrands do
resources :subsubbrands
end
Here is my brand.rb model
class Brand < ActiveRecord::Base
validates :name, :presence => true
has_many :subbrands
has_many :subsubbrands, :through => :subrands
end
...and my subbrand.rb model
class Subbrand < ActiveRecord::Base
validates :name, :presence => true
belongs_to :brand
has_many :subsubbrands
end