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
|
class ApplicationController < ActionController::Base
|
||||||
session :session_key => '_barleysodas_session_id'
|
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.
|
# Sane error and missing document messages.
|
||||||
#
|
#
|
||||||
|
|
|
@ -34,6 +34,7 @@ class BeersController < ApplicationController
|
||||||
# GET /beers/1;edit
|
# GET /beers/1;edit
|
||||||
def edit
|
def edit
|
||||||
@secondary_title = 'Update existing beer'
|
@secondary_title = 'Update existing beer'
|
||||||
|
@brewery = @beer.brewery
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /beers
|
# POST /beers
|
||||||
|
@ -42,6 +43,8 @@ class BeersController < ApplicationController
|
||||||
@beer = Beer.new(params[:beer])
|
@beer = Beer.new(params[:beer])
|
||||||
@page = Page.new(params[:page])
|
@page = Page.new(params[:page])
|
||||||
@beer.page = @page
|
@beer.page = @page
|
||||||
|
brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil
|
||||||
|
@beer.brewery = brewery
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @beer.save
|
if @beer.save
|
||||||
flash[:notice] = 'Beer was successfully created.'
|
flash[:notice] = 'Beer was successfully created.'
|
||||||
|
@ -58,9 +61,11 @@ class BeersController < ApplicationController
|
||||||
# PUT /beers/1
|
# PUT /beers/1
|
||||||
# PUT /beers/1.xml
|
# PUT /beers/1.xml
|
||||||
def update
|
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|
|
respond_to do |format|
|
||||||
@page.attributes = params[:page]
|
|
||||||
@beer.attributes = params[:beer]
|
|
||||||
if @beer.save
|
if @beer.save
|
||||||
flash[:notice] = 'Beer was successfully updated.'
|
flash[:notice] = 'Beer was successfully updated.'
|
||||||
format.html { redirect_to beer_url(@beer.page.title_for_url) }
|
format.html { redirect_to beer_url(@beer.page.title_for_url) }
|
||||||
|
@ -84,6 +89,9 @@ class BeersController < ApplicationController
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
##
|
||||||
|
# Fetches the Beer and Page model for the actions.
|
||||||
|
#
|
||||||
def get_beer_and_page
|
def get_beer_and_page
|
||||||
@beer = Beer.find_by_title(Page.title_from_url(params[:id]),
|
@beer = Beer.find_by_title(Page.title_from_url(params[:id]),
|
||||||
:include => [ 'page' ])
|
:include => [ 'page' ])
|
||||||
|
|
|
@ -13,6 +13,9 @@ class Beer < ActiveRecord::Base
|
||||||
#
|
#
|
||||||
def page_attributes
|
def page_attributes
|
||||||
pattr = []
|
pattr = []
|
||||||
|
unless brewery.nil?
|
||||||
|
pattr << "Brewery: #{brewery.title}"
|
||||||
|
end
|
||||||
pattr << "ABV: #{"%.1f" % abv}%" unless abv.to_s.empty?
|
pattr << "ABV: #{"%.1f" % abv}%" unless abv.to_s.empty?
|
||||||
unless original_gravity.to_s.empty?
|
unless original_gravity.to_s.empty?
|
||||||
pattr << "Original Gravity: #{original_gravity}"
|
pattr << "Original Gravity: #{original_gravity}"
|
||||||
|
|
|
@ -10,4 +10,7 @@
|
||||||
<p>
|
<p>
|
||||||
<label for="beer_final_gravity">Final Gravity</label> <%= text_field 'beer', 'final_gravity' %>
|
<label for="beer_final_gravity">Final Gravity</label> <%= text_field 'beer', 'final_gravity' %>
|
||||||
</p>
|
</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' %>
|
<%= render :partial => 'pages/page_form' %>
|
||||||
|
|
Reference in New Issue