From 6fc4b1c30e1cc024bb0f6e5575725f2c11420e1f Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 3 Feb 2008 01:28:48 +0000 Subject: [PATCH] adding feeds into beer experiences git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@123 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7 --- app/controllers/experiences_controller.rb | 30 ++++++++++++++--------- app/views/experiences/_experiences.rhtml | 17 +++++++++++++ db/migrate/014_create_experiences.rb | 1 + 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 app/views/experiences/_experiences.rhtml diff --git a/app/controllers/experiences_controller.rb b/app/controllers/experiences_controller.rb index 87fc9ee..7e926dd 100644 --- a/app/controllers/experiences_controller.rb +++ b/app/controllers/experiences_controller.rb @@ -9,20 +9,26 @@ class ExperiencesController < ApplicationController # GET /experiences/1 # GET /experiences/1.xml def show + @content_title = 'Experience Points' @people = People.find_by_title(Page.title_from_url(params[:id])) - cond_ary = [ 'experiences.people_id = :people_id' ] - cond_var = { :people_id => @people.id } - conditions = [ cond_ary.join(' AND '), cond_var ] - @total_count = Experience.count(conditions) - @pages, @experiences = paginate :experiences, - :include => [ 'beer' ], :order => [ 'beers.title ASC' ], - :per_page => per_page, :conditions => conditions - brewery_ids = @experiences.collect { |e| e.beer.brewery_id } - @breweries = Brewery.find(brewery_ids, :order => 'title ASC') - flash.now[:notice] = 'No experience yet.' if @experiences.empty? respond_to do |format| - format.html # index.rhtml - format.xml { render :xml => @experiences.to_xml } + format.html do + cond_ary = [ 'experiences.people_id = :people_id' ] + cond_var = { :people_id => @people.id } + conditions = [ cond_ary.join(' AND '), cond_var ] + @total_count = Experience.count("people_id = #{@people.id}") + @pages, @experiences = paginate :experiences, + :include => [ 'beer' ], :order => [ 'beers.title ASC' ], + :per_page => per_page, :conditions => conditions + brewery_ids = @experiences.collect { |e| e.beer.brewery_id } + @breweries = Brewery.find(brewery_ids, :order => 'title ASC') + flash.now[:notice] = 'No experience yet.' if @experiences.empty? + end + format.rss do + @experiences = @people.experiences.find :all, :limit => per_page, + :order => 'created_at DESC' + render :partial => 'experiences' + end end end diff --git a/app/views/experiences/_experiences.rhtml b/app/views/experiences/_experiences.rhtml new file mode 100644 index 0000000..6a28e53 --- /dev/null +++ b/app/views/experiences/_experiences.rhtml @@ -0,0 +1,17 @@ + + + + <%= @people.title -%>'s Beers + <%= experience_path(@people.page.title_for_url) -%> + Most recently added beers + <%= @experiences.first.created_at rescue '' -%> +<% for experience in @experiences -%> + + <%= experience.beer.title -%> + <%= show_beer_link(experience.beer) -%> + <%= experience.beer.brewery.title -%> + <%= experience.created_at -%> + +<% end -%> + + \ No newline at end of file diff --git a/db/migrate/014_create_experiences.rb b/db/migrate/014_create_experiences.rb index 32a1ca1..dffbfe6 100644 --- a/db/migrate/014_create_experiences.rb +++ b/db/migrate/014_create_experiences.rb @@ -4,6 +4,7 @@ class CreateExperiences < ActiveRecord::Migration t.column :people_id, :integer t.column :beer_id, :integer t.column :rating, :integer + t.column :created_at, :timestamp end add_index :experiences, :people_id add_index :experiences, :beer_id