diff --git a/app/helpers/beers_helper.rb b/app/helpers/beers_helper.rb index d713278..8bcf488 100644 --- a/app/helpers/beers_helper.rb +++ b/app/helpers/beers_helper.rb @@ -1,5 +1,2 @@ module BeersHelper - def abv(beer) - number_to_percentage(beer.abv, { :precision => 1 }) - end end diff --git a/app/models/beer.rb b/app/models/beer.rb index c24cca8..5727b68 100644 --- a/app/models/beer.rb +++ b/app/models/beer.rb @@ -8,6 +8,21 @@ class Beer < ActiveRecord::Base before_save :ensure_page_valid after_save :save_page + ## + # Returns a list of attributes for the Page partial. + # + def page_attributes + pattr = [] + pattr << "ABV: #{"%.1f" % abv}%" unless abv.to_s.empty? + unless original_gravity.to_s.empty? + pattr << "Original Gravity: #{original_gravity}" + end + unless final_gravity.to_s.empty? + pattr << "Final Gravity: #{final_gravity}" + end + pattr + end + protected ## diff --git a/app/models/brewery.rb b/app/models/brewery.rb index 5d55994..8263782 100644 --- a/app/models/brewery.rb +++ b/app/models/brewery.rb @@ -8,6 +8,15 @@ class Brewery < ActiveRecord::Base before_save :ensure_page_valid after_save :save_page + ## + # Returns a list of attributes to add into the Page display. + # + def page_attributes + pattr = [] + pattr << "Available Beers: #{beers.size}" + pattr + end + protected ## diff --git a/app/views/beers/show.rhtml b/app/views/beers/show.rhtml index 8b0de59..4ee0cb3 100644 --- a/app/views/beers/show.rhtml +++ b/app/views/beers/show.rhtml @@ -1,18 +1,5 @@ <%= render :partial => 'pages/page' %> -<% - attributes = [] - attributes << "ABV: #{abv(@beer)}" unless @beer.abv.to_s.empty? - attributes << "Original Gravity: #{@beer.original_gravity}" unless @beer.original_gravity.to_s.empty? - attributes << "Final Gravity: #{@beer.final_gravity}" unless @beer.final_gravity.to_s.empty? - unless attributes.empty? --%> -
-

Useful attributes

- -
-<% end -%> - <% content_for :sidebar do -%> <%= link_to 'New Beer', new_beer_path -%>
<%= link_to 'Edit Beer', edit_beer_path(@beer.page.title_for_url) -%>
diff --git a/app/views/breweries/show.rhtml b/app/views/breweries/show.rhtml index 4021e60..974146a 100644 --- a/app/views/breweries/show.rhtml +++ b/app/views/breweries/show.rhtml @@ -1,11 +1,5 @@ <%= render :partial => 'pages/page' %> -
- -
- <% content_for :sidebar do -%> <%= link_to 'New Brewery', new_brewery_path -%>
<%= link_to 'Edit', edit_brewery_path(@brewery.page.title_for_url) -%>
diff --git a/app/views/pages/_page.rhtml b/app/views/pages/_page.rhtml index 1175ba5..cb24886 100644 --- a/app/views/pages/_page.rhtml +++ b/app/views/pages/_page.rhtml @@ -12,8 +12,9 @@ - \ No newline at end of file +