Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new (SQL) views

  • Loading branch information...
commit cc552f6792139d975d6185e6029e1fefdbc0bc26 1 parent f41c140
Anand Iyer authored
2  Gemfile
View
@@ -7,7 +7,7 @@ gem 'rails', '3.0.7'
gem 'sqlite3'
gem 'pg'
-
+gem "will_paginate", "~> 3.0.pre2"
group :production do
gem 'rack-google_analytics', :require => "rack/google_analytics"
2  Gemfile.lock
View
@@ -66,6 +66,7 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.27)
+ will_paginate (3.0.pre2)
PLATFORMS
ruby
@@ -75,3 +76,4 @@ DEPENDENCIES
rack-google_analytics
rails (= 3.0.7)
sqlite3
+ will_paginate (~> 3.0.pre2)
19 app/controllers/i_tunes_games_controller.rb
View
@@ -2,7 +2,7 @@ class ITunesGamesController < ApplicationController
# GET /i_tunes_games
# GET /i_tunes_games.xml
def index
- @i_tunes_games = ITunesGame.all(:select => "DISTINCT \"i_tunes_games\".\"iTunesId\"", :limit => 100)
+ @i_tunes_games = ITunesGame.paginate(:page => params[:page], :select => "DISTINCT \"i_tunes_games\".\"iTunesId\"")
respond_to do |format|
format.html # index.html.erb
@@ -11,8 +11,19 @@ def index
end
end
+ def details
+ @i_tunes_games = ITunesGame.paginate(:page => params[:page],
+ :conditions => "\"i_tunes_games\".\"iTunesId\" = " + params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @i_tunes_games }
+ format.json { render :json => @i_tunes_games }
+ end
+ end
+
def user
- @i_tunes_games = ITunesGame.find(:all,
+ @i_tunes_games = ITunesGame.paginate(:page => params[:page],
:conditions => "\"i_tunes_games\".\"uid\" = " + params[:id])
respond_to do |format|
@@ -23,7 +34,7 @@ def user
end
def itunes
- @i_tunes_games = ITunesGame.find(:all,
+ @i_tunes_games = ITunesGame.paginate(:page => params[:page],
:conditions => "\"i_tunes_games\".\"iTunesId\" = " + params[:id])
respond_to do |format|
@@ -36,7 +47,7 @@ def itunes
# GET /i_tunes_games/1
# GET /i_tunes_games/1.xml
def show
- @i_tunes_games = ITunesGame.find(:all,
+ @i_tunes_games = ITunesGame.paginate(:page => params[:page],
:conditions => "\"i_tunes_games\".\"iTunesId\" = " + params[:id])
respond_to do |format|
2  app/models/i_tunes_game.rb
View
@@ -1,2 +1,4 @@
class ITunesGame < ActiveRecord::Base
+ cattr_reader :per_page
+ @@per_page = 50
end
18 app/views/i_tunes_games/details.html.erb
View
@@ -0,0 +1,18 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>iTunesId:</b>
+ <%= @i_tunes_game.iTunesId %>
+</p>
+
+<p>
+ <b>Rating:</b>
+ <%= @i_tunes_game.rating %>
+</p>
+
+<p>
+ <b>Number of Reviews:</b>
+ <%= @i_tunes_game.rating %>
+</p>
+
+<%= link_to 'Back', i_tunes_games_path %>
3  app/views/i_tunes_games/index.html.erb
View
@@ -11,5 +11,6 @@
</tr>
<% end %>
</table>
-
+<%= will_paginate @i_tunes_games %>
+<%= page_entries_info @i_tunes_games %>
<br />
2  app/views/i_tunes_games/itunes.html.erb
View
@@ -23,3 +23,5 @@
</table>
<br />
+<%= will_paginate @i_tunes_games %>
+<%= page_entries_info @i_tunes_games %>
2  app/views/i_tunes_games/show.html.erb
View
@@ -35,6 +35,4 @@
<%= @i_tunes_game.review %>
</p>
-
-<%= link_to 'Edit', edit_i_tunes_game_path(@i_tunes_game) %> |
<%= link_to 'Back', i_tunes_games_path %>
6 app/views/i_tunes_games/user.html.erb
View
@@ -6,7 +6,6 @@
<th>Review</th>
<th></th>
<th></th>
- <th></th>
</tr>
<% @i_tunes_games.each do |i_tunes_game| %>
@@ -15,9 +14,10 @@
<td><a href="/itunes/<%= i_tunes_game.iTunesId %>"><%= i_tunes_game.iTunesId %></a></td>
<td><%= i_tunes_game.helpful %>/<%= i_tunes_game.numhelpful %></td>
<td><%= i_tunes_game.review %></td>
- <td><%= link_to 'Show', i_tunes_game %></td>
</tr>
<% end %>
</table>
-<br />
+<br />
+<%= will_paginate @i_tunes_games %>
+<%= page_entries_info @i_tunes_games %>
14 db/migrate/20110605032714_create_averages_view.rb
View
@@ -0,0 +1,14 @@
+class CreateAveragesView < ActiveRecord::Migration
+ def self.up
+ execute <<-SQL
+ CREATE VIEW averages AS
+ SELECT "i_tunes_games"."iTunesId" AS iTunesId, AVG("i_tunes_games"."rating") AS avg_rating, COUNT(*) AS count
+ FROM "i_tunes_games"
+ GROUP BY "i_tunes_games"."iTunesId"
+ SQL
+ end
+
+ def self.down
+ DROP VIEW averages
+ end
+end
1  public/google929b8bd1e9f42465.html
View
@@ -0,0 +1 @@
+google-site-verification: google929b8bd1e9f42465.html
Please sign in to comment.
Something went wrong with that request. Please try again.