adding brewery association
git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@35 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7master
parent
ef4b7b07a8
commit
f3c9f85e1d
|
@ -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.
|
||||
#
|
||||
|
|
|
@ -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
|
||||
@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|
|
||||
@page.attributes = params[:page]
|
||||
@beer.attributes = params[:beer]
|
||||
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' ])
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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' %>
|
||||
|
|
|
@ -34,4 +34,4 @@ pre {
|
|||
white-space: -pre-wrap;
|
||||
white-space: -o-pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue