From 2003fe1d528d40f11fcc8e57e8e7d1d7d86c2c70 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 7 Feb 2008 04:26:02 +0000 Subject: [PATCH] using brewery name in refernce to the beer git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@148 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7 --- app/controllers/beers_controller.rb | 6 ++++-- app/controllers/tag_images_controller.rb | 7 ++++++- app/helpers/beers_helper.rb | 2 ++ app/models/beer.rb | 4 ++++ app/views/beers/index.rhtml | 5 ++++- app/views/tag_images/_tag_images.rhtml | 4 ++-- app/views/tag_images/_taggable_results.rhtml | 2 +- 7 files changed, 23 insertions(+), 7 deletions(-) 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 -%> +

<%= show_brewery_link(brewery) -%>

+<% end -%> <%= render :partial => 'shared/pagination_links' %> diff --git a/app/views/tag_images/_tag_images.rhtml b/app/views/tag_images/_tag_images.rhtml index a4fc2dd..bf01259 100644 --- a/app/views/tag_images/_tag_images.rhtml +++ b/app/views/tag_images/_tag_images.rhtml @@ -3,8 +3,8 @@ <% if @tag_images.empty? -%> None. <% elsif (read_only ||= false) -%> - <%= @tag_images.collect { |t| "#{t.tagged.title} (#{t.tagged_type})" }.join(', ') %> + <%= @tag_images.collect { |t| "#{(t.tagged.respond_to?(:name) ? t.tagged.name : t.tagged.title)} (#{t.tagged_type})" }.join(', ') %> <% else -%> - <%= @tag_images.collect { |t| "#{t.tagged.title} (#{t.tagged_type} | #{link_to_remote('Remove', :url => tag_image_path(t), :update => 'tag_images', :method => :delete)})" }.join(', ') -%> + <%= @tag_images.collect { |t| "#{(t.tagged.respond_to?(:name) ? t.tagged.name : t.tagged.title)} (#{t.tagged_type} | #{link_to_remote('Remove', :url => tag_image_path(t), :update => 'tag_images', :method => :delete)})" }.join(', ') -%> <% end -%>

\ No newline at end of file diff --git a/app/views/tag_images/_taggable_results.rhtml b/app/views/tag_images/_taggable_results.rhtml index 3c96a98..2ccfe80 100644 --- a/app/views/tag_images/_taggable_results.rhtml +++ b/app/views/tag_images/_taggable_results.rhtml @@ -2,7 +2,7 @@ <% next if @results[ctype].empty? -%>

<%= ctype.pluralize -%>

- <%= @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? } -%>