adding brewery association

git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@35 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2007-11-17 07:12:50 +00:00
parent ef4b7b07a8
commit f3c9f85e1d
5 changed files with 25 additions and 3 deletions

View File

@ -1,6 +1,14 @@
class ApplicationController < ActionController::Base
session :session_key => '_barleysodas_session_id'
##
# Ensures that the request was made using an Ajax request.
#
def ensure_xhr
return false unless request.xhr?
true
end
##
# Sane error and missing document messages.
#

View File

@ -34,6 +34,7 @@ class BeersController < ApplicationController
# GET /beers/1;edit
def edit
@secondary_title = 'Update existing beer'
@brewery = @beer.brewery
end
# POST /beers
@ -42,6 +43,8 @@ class BeersController < ApplicationController
@beer = Beer.new(params[:beer])
@page = Page.new(params[:page])
@beer.page = @page
brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil
@beer.brewery = brewery
respond_to do |format|
if @beer.save
flash[:notice] = 'Beer was successfully created.'
@ -58,9 +61,11 @@ class BeersController < ApplicationController
# PUT /beers/1
# PUT /beers/1.xml
def update
respond_to do |format|
@page.attributes = params[:page]
@beer.attributes = params[:beer]
brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil
@beer.brewery = brewery
respond_to do |format|
if @beer.save
flash[:notice] = 'Beer was successfully updated.'
format.html { redirect_to beer_url(@beer.page.title_for_url) }
@ -84,6 +89,9 @@ class BeersController < ApplicationController
protected
##
# Fetches the Beer and Page model for the actions.
#
def get_beer_and_page
@beer = Beer.find_by_title(Page.title_from_url(params[:id]),
:include => [ 'page' ])

View File

@ -13,6 +13,9 @@ class Beer < ActiveRecord::Base
#
def page_attributes
pattr = []
unless brewery.nil?
pattr << "Brewery: #{brewery.title}"
end
pattr << "ABV: #{"%.1f" % abv}%" unless abv.to_s.empty?
unless original_gravity.to_s.empty?
pattr << "Original Gravity: #{original_gravity}"

View File

@ -10,4 +10,7 @@
<p>
<label for="beer_final_gravity">Final Gravity</label> <%= text_field 'beer', 'final_gravity' %>
</p>
<p>
<label for="brewery_title">Brewery</label> <%= text_field_with_auto_complete('brewery', 'title', {}, { :url => { :controller => 'autocomplete', :action => 'index' } }) %>
</p>
<%= render :partial => 'pages/page_form' %>