2007-11-11 01:33:08 -05:00
|
|
|
class BeersController < ApplicationController
|
2008-01-02 02:58:03 -05:00
|
|
|
append_before_filter :fetch_model,
|
|
|
|
:only => [ :show, :edit, :update, :destroy ]
|
2007-11-11 01:33:08 -05:00
|
|
|
|
|
|
|
# GET /beers
|
|
|
|
# GET /beers.xml
|
|
|
|
def index
|
2007-11-15 19:57:44 -05:00
|
|
|
@content_title = 'The Beers'
|
|
|
|
@secondary_title = 'Browsing all beers'
|
2008-01-16 11:31:57 -05:00
|
|
|
@pages, @beers = paginate :beers, :include => 'page', :per_page => per_page,
|
2007-11-11 01:33:08 -05:00
|
|
|
:order => 'beers.title ASC'
|
2007-11-28 02:16:41 -05:00
|
|
|
@tags = Page.tags(:limit => 25, :order => "name DESC",
|
|
|
|
:owner_type => 'Beer')
|
2007-11-11 01:33:08 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.rhtml
|
|
|
|
format.xml { render :xml => @beers.to_xml }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /beers/1
|
|
|
|
# GET /beers/1.xml
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.rhtml
|
|
|
|
format.xml { render :xml => @beer.to_xml }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /beers/new
|
|
|
|
def new
|
2008-01-06 23:01:57 -05:00
|
|
|
new_stuff
|
2007-11-11 01:33:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /beers/1;edit
|
|
|
|
def edit
|
2008-01-06 23:01:57 -05:00
|
|
|
edit_stuff
|
2007-11-11 01:33:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /beers
|
|
|
|
# POST /beers.xml
|
|
|
|
def create
|
2008-01-06 23:01:57 -05:00
|
|
|
new_stuff
|
2007-11-28 01:17:25 -05:00
|
|
|
allow_page_discussions
|
2008-01-06 23:01:57 -05:00
|
|
|
@page.attributes = params[:page]
|
|
|
|
@beer.attributes = params[:beer]
|
2008-01-07 00:46:43 -05:00
|
|
|
@beer.page = @page
|
2007-11-17 02:12:50 -05:00
|
|
|
brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil
|
|
|
|
@beer.brewery = brewery
|
2007-11-11 01:33:08 -05:00
|
|
|
respond_to do |format|
|
|
|
|
if @beer.save
|
|
|
|
flash[:notice] = 'Beer was successfully created.'
|
|
|
|
format.html { redirect_to beer_url(@beer.page.title_for_url) }
|
|
|
|
format.xml { head :created,
|
|
|
|
:location => beer_url(@beer.page.title_for_url) }
|
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
format.xml { render :xml => @beer.errors.to_xml }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /beers/1
|
|
|
|
# PUT /beers/1.xml
|
|
|
|
def update
|
2008-01-06 23:01:57 -05:00
|
|
|
edit_stuff
|
2007-11-17 02:12:50 -05:00
|
|
|
@page.attributes = params[:page]
|
|
|
|
@beer.attributes = params[:beer]
|
|
|
|
brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil
|
|
|
|
@beer.brewery = brewery
|
2007-11-11 01:33:08 -05:00
|
|
|
respond_to do |format|
|
|
|
|
if @beer.save
|
|
|
|
flash[:notice] = 'Beer was successfully updated.'
|
2007-11-12 00:38:13 -05:00
|
|
|
format.html { redirect_to beer_url(@beer.page.title_for_url) }
|
2007-11-11 01:33:08 -05:00
|
|
|
format.xml { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.xml { render :xml => @beer.errors.to_xml }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /beers/1
|
|
|
|
# DELETE /beers/1.xml
|
|
|
|
def destroy
|
|
|
|
@beer.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to beers_url }
|
|
|
|
format.xml { head :ok }
|
|
|
|
end
|
|
|
|
end
|
2008-01-06 23:01:57 -05:00
|
|
|
|
|
|
|
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
|
2008-01-07 00:46:43 -05:00
|
|
|
@beer.page = @page
|
2008-01-06 23:01:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit_stuff
|
|
|
|
@secondary_title = 'Update existing beer'
|
|
|
|
@brewery = @beer.brewery
|
|
|
|
end
|
2007-11-11 01:33:08 -05:00
|
|
|
end
|