diff --git a/app/controllers/application.rb b/app/controllers/application.rb index fadfaaf..23784eb 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -108,8 +108,8 @@ class ApplicationController < ActionController::Base obj = Class.class_eval(obj_name.camelize).find(:first, :conditions => [ cond_ary.join(' AND '), cond_var ]) - # allow the chance to make a new one if you GET the URL - if request.get? and obj.nil? + # allow the chance to make a new one if you GET the URL, but not for Style + if request.get? and obj.nil? and obj_type != 'styles' flash[:info] = "The #{obj_name} was not found, would you like to make it?" redirect_to :action => 'new', :new_title => tfu return diff --git a/app/controllers/beers_controller.rb b/app/controllers/beers_controller.rb index 14612ca..9b1e66b 100644 --- a/app/controllers/beers_controller.rb +++ b/app/controllers/beers_controller.rb @@ -43,6 +43,7 @@ class BeersController < ApplicationController allow_page_discussions @page.attributes = params[:page] @beer.attributes = params[:beer] + @beer.page = @page brewery = Brewery.find_by_title(params[:brewery][:title]) rescue nil @beer.brewery = brewery respond_to do |format| @@ -95,6 +96,7 @@ class BeersController < ApplicationController @beer = Beer.new @beer.title = params[:new_title] if params[:new_title] @page = Page.new + @beer.page = @page end def edit_stuff diff --git a/app/controllers/styles_controller.rb b/app/controllers/styles_controller.rb new file mode 100644 index 0000000..09ed760 --- /dev/null +++ b/app/controllers/styles_controller.rb @@ -0,0 +1,98 @@ +class StylesController < ApplicationController + append_before_filter :fetch_model, + :only => [ :show, :edit, :update, :destroy ] + + # GET /styles + # GET /styles.xml + def index + @content_title = 'Beverage Styles' + @secondary_title = 'Major Style Categories' + @styles = Style.major_styles + @tags = Page.tags(:limit => 25, :order => "name DESC", + :owner_type => 'Style') + respond_to do |format| + format.html # index.rhtml + format.xml { render :xml => @styles.to_xml } + end + end + + # GET /styles/1 + # GET /styles/1.xml + def show + @children = @style.children + respond_to do |format| + format.html # show.rhtml + format.xml { render :xml => @style.to_xml } + end + end + + # GET /styles/new + def new + new_stuff + end + + # GET /styles/1;edit + def edit + edit_stuff + end + + # POST /styles + # POST /styles.xml + def create + new_stuff + @style.attributes = params[:style] + @page.attributes = params[:page] + respond_to do |format| + if @style.save + flash[:notice] = 'Style was successfully created.' + format.html { redirect_to style_url(@style.page.title_for_url) } + format.xml { head :created, :location => style_url(@style) } + else + format.html { render :action => "new" } + format.xml { render :xml => @style.errors.to_xml } + end + end + end + + # PUT /styles/1 + # PUT /styles/1.xml + def update + edit_stuff + @style.attributes = params[:style] + @page.attributes = params[:page] + @style.page = @page + respond_to do |format| + if @style.save + flash[:notice] = 'Style was successfully updated.' + format.html { redirect_to style_url(@style.page.title_for_url) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @style.errors.to_xml } + end + end + end + + # DELETE /styles/1 + # DELETE /styles/1.xml + def destroy + @style.destroy + respond_to do |format| + format.html { redirect_to styles_url } + format.xml { head :ok } + end + end + + protected + + def new_stuff + @secondary_title = 'New Style' + @style = Style.new + @page = Page.new + @style.page = @page + end + + def edit_stuff + @secondary_title = 'Update Style' + end +end diff --git a/app/helpers/styles_helper.rb b/app/helpers/styles_helper.rb new file mode 100644 index 0000000..0c75adf --- /dev/null +++ b/app/helpers/styles_helper.rb @@ -0,0 +1,15 @@ +module StylesHelper + def new_style_link + link_to 'New Style', new_style_path, { :title => 'Create a new style' } + end + + def show_style_link(style) + link_to style.title, style_path(style.page.title_for_url), + { :title => style.title } + end + + def edit_style_link(style) + link_to 'Edit Style', edit_style_path(style.page.title_for_url), + { :title => "Edit #{style.title}" } + end +end diff --git a/app/models/beer.rb b/app/models/beer.rb index a0ac8c0..8a9dab5 100644 --- a/app/models/beer.rb +++ b/app/models/beer.rb @@ -4,6 +4,8 @@ class Beer < ActiveRecord::Base belongs_to :brewery has_one_tuxwiki_page :owner_class => 'Beer' + belongs_to :style + validates_presence_of :style_id ## # Returns a list of attributes for the Page partial. @@ -20,6 +22,7 @@ class Beer < ActiveRecord::Base unless final_gravity.to_s.empty? pattr << "Final Gravity: #{final_gravity}" end + pattr << "Style: #{style.title}" pattr end end diff --git a/app/views/beers/_beer_form.rhtml b/app/views/beers/_beer_form.rhtml index 421b314..c8fb9fb 100644 --- a/app/views/beers/_beer_form.rhtml +++ b/app/views/beers/_beer_form.rhtml @@ -10,6 +10,9 @@
<%= text_field 'beer', 'final_gravity' %>
++ <%= select 'beer', 'style_id', Style.for_select, { :selected => @beer.style_id } %> +
<%= text_field_with_auto_complete('brewery', 'title', {}, { :url => { :controller => 'autocomplete', :action => 'index' } }) %>
diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index f60bb9e..c716b02 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -34,6 +34,7 @@