adding before filters to set up page variables

git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@77 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2008-01-07 04:01:57 +00:00
parent 56abbbfe8d
commit fb11eb1d47
1 changed files with 20 additions and 11 deletions

View File

@ -9,10 +9,8 @@ class BeersController < ApplicationController
@secondary_title = 'Browsing all beers' @secondary_title = 'Browsing all beers'
@pages, @beers = paginate :beers, :include => 'page', :per_page => 50, @pages, @beers = paginate :beers, :include => 'page', :per_page => 50,
:order => 'beers.title ASC' :order => 'beers.title ASC'
@tags = Page.tags(:limit => 25, :order => "name DESC", @tags = Page.tags(:limit => 25, :order => "name DESC",
:owner_type => 'Beer') :owner_type => 'Beer')
respond_to do |format| respond_to do |format|
format.html # index.rhtml format.html # index.rhtml
format.xml { render :xml => @beers.to_xml } format.xml { render :xml => @beers.to_xml }
@ -30,25 +28,21 @@ class BeersController < ApplicationController
# GET /beers/new # GET /beers/new
def new def new
@secondary_title = 'Create a new beer' new_stuff
@beer = Beer.new
@beer.title = params[:new_title] if params[:new_title]
@page = Page.new
end end
# GET /beers/1;edit # GET /beers/1;edit
def edit def edit
@secondary_title = 'Update existing beer' edit_stuff
@brewery = @beer.brewery
end end
# POST /beers # POST /beers
# POST /beers.xml # POST /beers.xml
def create def create
@beer = Beer.new(params[:beer]) new_stuff
@page = Page.new(params[:page])
@beer.page = @page
allow_page_discussions allow_page_discussions
@page.attributes = params[:page]
@beer.attributes = params[:beer]
brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil
@beer.brewery = brewery @beer.brewery = brewery
respond_to do |format| respond_to do |format|
@ -67,6 +61,7 @@ class BeersController < ApplicationController
# PUT /beers/1 # PUT /beers/1
# PUT /beers/1.xml # PUT /beers/1.xml
def update def update
edit_stuff
@page.attributes = params[:page] @page.attributes = params[:page]
@beer.attributes = params[:beer] @beer.attributes = params[:beer]
brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil
@ -92,4 +87,18 @@ class BeersController < ApplicationController
format.xml { head :ok } format.xml { head :ok }
end end
end end
protected
def new_stuff
@secondary_title = 'Create a new beer'
@beer = Beer.new
@beer.title = params[:new_title] if params[:new_title]
@page = Page.new
end
def edit_stuff
@secondary_title = 'Update existing beer'
@brewery = @beer.brewery
end
end end