Permalink
Browse files

add the info controller to generate lists of customers who bought a s…

…pecific product
  • Loading branch information...
1 parent 552df27 commit db65f96da973ab95c37d9fb625084e3e11ef32e9 @tomcz tomcz committed Mar 10, 2010
@@ -0,0 +1,17 @@
+class InfoController < ApplicationController
+
+ def who_bought
+ @product = Product.find(params[:id])
+ @orders = @product.orders
+ respond_to do |format|
+ format.html
+ format.xml { render :layout => false }
+ end
+ end
+
+ protected
+
+ def authorize
+ end
+
+end
@@ -0,0 +1,2 @@
+module InfoHelper
+end
View
@@ -3,6 +3,9 @@ class Product < ActiveRecord::Base
set_primary_key :uuid
include UUIDHelper
+ has_many :line_items
+ has_many :orders, :through => :line_items
+
validates_presence_of :title, :description, :image_url
validates_uniqueness_of :title
@@ -0,0 +1,4 @@
+%h3 People who bought #{h @product.title}
+%ul
+ - for order in @orders
+ %li= mail_to order.email, order.name
@@ -0,0 +1,8 @@
+xml.order_list(:for_product => @product.title) do
+ for order in @orders
+ xml.order do
+ xml.name(order.name)
+ xml.email(order.email)
+ end
+ end
+end
@@ -0,0 +1,7 @@
+!!!
+%html(xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en")
+ %head
+ %meta(http-equiv="content-type" content="text/html;charset=UTF-8")
+ %title Pragprog Books Online Store
+ %body
+ = yield
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class InfoControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class InfoHelperTest < ActionView::TestCase
+end

0 comments on commit db65f96

Please sign in to comment.