diff --git a/app/controllers/beers_controller.rb b/app/controllers/beers_controller.rb index 44279a9..2243d80 100644 --- a/app/controllers/beers_controller.rb +++ b/app/controllers/beers_controller.rb @@ -9,8 +9,10 @@ class BeersController < ApplicationController format.html do @content_title = 'The Beers' @secondary_title = 'Browsing all beers' - @pages, @beers = paginate :beers, :include => 'page', :per_page => per_page, - :order => 'beers.title ASC' + @pages, @beers = paginate :beers, :include => [ 'page', 'brewery' ], + :order => 'breweries.title ASC, beers.title ASC', + :per_page => per_page + @breweries = @beers.collect { |b| b.brewery }.uniq flash.now[:notice] = 'There are no beers yet.' if @beers.empty? @tags = Page.tags(:limit => 25, :order => "name DESC", :owner_type => 'Beer') diff --git a/app/controllers/tag_images_controller.rb b/app/controllers/tag_images_controller.rb index 367e339..afe5155 100644 --- a/app/controllers/tag_images_controller.rb +++ b/app/controllers/tag_images_controller.rb @@ -49,11 +49,16 @@ class TagImagesController < ApplicationController @results = {} cond_ary = [ 'title ILIKE :title' ] cond_var = { :title => "%#{params[:name]}%" } + limit = 50 TagImage.types_for_select.flatten.each do |ctype| + next if ctype == 'Beer' klass = Class.class_eval(ctype) @results[ctype] = klass.find :all, :order => 'title ASC', - :conditions => [ cond_ary.join(' AND '), cond_var ] + :conditions => [ cond_ary.join(' AND '), cond_var ], :limit => limit end + @results['Beer'] = Beer.find :all, :include => [ 'brewery' ], + :order => 'breweries.title ASC, beers.title ASC', :limit => limit, + :conditions => [ 'beers.title ILIKE :title OR breweries.title ILIKE :title', cond_var ] render :partial => 'taggable_results' end diff --git a/app/helpers/beers_helper.rb b/app/helpers/beers_helper.rb index d96bedf..4dc4b11 100644 --- a/app/helpers/beers_helper.rb +++ b/app/helpers/beers_helper.rb @@ -1,4 +1,6 @@ module BeersHelper + include BreweriesHelper + def new_beer_link link_to 'New Beer', new_beer_path, { :title => 'Create a new beer' } end diff --git a/app/models/beer.rb b/app/models/beer.rb index 58e5820..46df8c6 100644 --- a/app/models/beer.rb +++ b/app/models/beer.rb @@ -10,6 +10,10 @@ class Beer < ActiveRecord::Base has_many :experiences, :dependent => :destroy has_many :people, :through => :experiences + def name + "#{self.brewery.title} :: #{self.title}" + end + ## # Returns a list of attributes for the Page partial. # diff --git a/app/views/beers/index.rhtml b/app/views/beers/index.rhtml index fb61ea3..dbb90f5 100644 --- a/app/views/beers/index.rhtml +++ b/app/views/beers/index.rhtml @@ -1,6 +1,9 @@ +<% for brewery in @breweries -%> +
- <%= @results[ctype].collect { |r| link_to_function(r.title, "set_taggable_item(#{r.id}, '#{r.title}', '#{ctype}');") }.join(', ') %> + <%= @results[ctype].collect { |r| link_to_function((r.respond_to?(:name) ? r.name : r.title), "set_taggable_item(#{r.id}, '#{(r.respond_to?(:name) ? r.name : r.title)}', '#{ctype}');") }.join(', ') %>
<% end -%> <% unless @results.detect { |key, val| !val.empty? } -%>