Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Created July 1, 2012 18:51
Show Gist options
  • Save nicholasjhenry/3029227 to your computer and use it in GitHub Desktop.
Save nicholasjhenry/3029227 to your computer and use it in GitHub Desktop.
def index
@stockist_countries = StockistCountry.active_stockists
end
<% @stockist_countries.each do |country| %>
<div class="individual-stockist">
<%= content_tag(:h2, country.name) %>
<% country.stockists.each do |stockist| %>
<%= "Position: #{stockist.position}" %><br />
<%= stockist.name %><br />
<%= link_to(stockist.url, stockist.url) %>
<% end %>
</div>
<% end %>
belongs_to :stockist_country
acts_as_list :scope => :stockist_country
attr_accessible :name, :position, :active
has_many :stockists, :dependent => :destroy
acts_as_list
def self.active
where(:'countries.active' => true)
end
def self.order_by_position
order('countries.position')
end
def self.active_stockists
active.order_by_position.includes(:stockists).where('stockists.active' => true).order('stockists_country.position, stockists.position')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment