using brewery name in refernce to the beer

git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@148 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2008-02-07 04:26:02 +00:00
parent bdbe5cb319
commit 2003fe1d52
7 changed files with 23 additions and 7 deletions

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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.
#

View File

@ -1,6 +1,9 @@
<% for brewery in @breweries -%>
<h4><%= show_brewery_link(brewery) -%></h4>
<ul>
<% for beer in @beers %><li><%= link_to beer.title, beer_path(beer.page.title_for_url) %></li><% end %>
<% for beer in @beers.select { |b| b.brewery_id == brewery.id } -%><li><%= show_beer_link(beer) -%></li><% end %>
</ul>
<% end -%>
<%= render :partial => 'shared/pagination_links' %>

View File

@ -3,8 +3,8 @@
<% if @tag_images.empty? -%>
None.
<% elsif (read_only ||= false) -%>
<%= @tag_images.collect { |t| "<span onmouseover=\"show_tag_at(#{t.x}, #{t.y})\" onmouseout=\"hide_tag_box()\">#{t.tagged.title} (<em>#{t.tagged_type}</em>)</span>" }.join(', ') %>
<%= @tag_images.collect { |t| "<span onmouseover=\"show_tag_at(#{t.x}, #{t.y})\" onmouseout=\"hide_tag_box()\">#{(t.tagged.respond_to?(:name) ? t.tagged.name : t.tagged.title)} (<em>#{t.tagged_type}</em>)</span>" }.join(', ') %>
<% else -%>
<%= @tag_images.collect { |t| "<span onmouseover=\"show_tag_at(#{t.x}, #{t.y})\" onmouseout=\"hide_tag_box()\">#{t.tagged.title} (<em>#{t.tagged_type}</em> | #{link_to_remote('Remove', :url => tag_image_path(t), :update => 'tag_images', :method => :delete)})</span>" }.join(', ') -%>
<%= @tag_images.collect { |t| "<span onmouseover=\"show_tag_at(#{t.x}, #{t.y})\" onmouseout=\"hide_tag_box()\">#{(t.tagged.respond_to?(:name) ? t.tagged.name : t.tagged.title)} (<em>#{t.tagged_type}</em> | #{link_to_remote('Remove', :url => tag_image_path(t), :update => 'tag_images', :method => :delete)})</span>" }.join(', ') -%>
<% end -%>
</p>

View File

@ -2,7 +2,7 @@
<% next if @results[ctype].empty? -%>
<h3><%= ctype.pluralize -%></h3>
<p>
<%= @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(', ') %>
</p>
<% end -%>
<% unless @results.detect { |key, val| !val.empty? } -%>