Created
July 1, 2012 18:51
-
-
Save nicholasjhenry/3029227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
@stockist_countries = StockistCountry.active_stockists | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
belongs_to :stockist_country | |
acts_as_list :scope => :stockist_country |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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