Commit 4df77c90
Changed files (28)
app
views
authentications
home
kaminari
profiles
registrations
search
config
initializers
spec
controllers
support
app/controllers/creations_controller.rb
@@ -3,7 +3,7 @@ class CreationsController < ApplicationController
# GET /creations
# GET /creations.xml
def index
- @creations = Creation.all
+ @creations = Creation.page(params[:page]).per(6)
respond_to do |format|
format.html # index.html.erb
app/controllers/home_controller.rb
@@ -1,10 +1,5 @@
class HomeController < ApplicationController
def index
@creations = Creation.all.reverse.take(4)
-
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @creations }
- end
end
end
app/controllers/profiles_controller.rb
@@ -2,7 +2,7 @@ class ProfilesController < ApplicationController
before_filter :authenticate_user!, :except => [:show]
def index
- @profiles = User.all
+ @profiles = User.page(params[:page]).per(10)
end
def show
app/controllers/search_controller.rb
@@ -1,6 +1,6 @@
class SearchController < ApplicationController
def index
- @creations = Creation.search params[:q], :include => :user, :match_mode => :extended, :star => true, :page => 1, :per_page => 20
+ @creations = Creation.search(params[:q], :include => :user, :match_mode => :extended, :star => true).page(params[:page]).per(6)
@search = params[:q]
end
end
app/views/authentications/index.html.erb
@@ -1,3 +1,6 @@
+<% content_for :title do %>
+ My Authentications
+<% end %>
<% if @authentications %>
<% unless @authentications.empty? %>
app/views/creations/edit.html.erb
@@ -1,3 +1,6 @@
+<% content_for :title do %>
+ Editing creation <%= @creation.name %>
+<% end %>
<% content_for :script do %>
$('label[data-editable="false"]').addClass('hidden');
$('input[data-editable="false"]').addClass('hidden');
app/views/creations/index.html.erb
@@ -1,3 +1,6 @@
+<% content_for :title do %>
+ Browse All Creations
+<% end %>
<h1>Browse All Creations</h1>
<p><em>What time is it? Nana, nana, naaaaana caake time!</em></p>
<p>Check out our communities most recent cake work.</p>
@@ -11,3 +14,6 @@
<p><%= creation.short_story %> <%= link_to 'more', creation %></p>
</div>
<% end %>
+
+<hr class="clear" />
+<p> <%= paginate @creations %> </p>
app/views/creations/mine.html.erb
@@ -1,3 +1,6 @@
+<% content_for :title do %>
+ My Creations
+<% end %>
<%= link_to "share my creation", new_creation_path(@creation), :class => 'floatRight' %>
<h1>My Creations</h1>
app/views/creations/new.html.erb
@@ -1,3 +1,6 @@
+<% content_for :title do %>
+ Share my creation
+<% end %>
<h1>Share your creation with other Cake artists, enthusiasts, and eaters!</h1>
<p>We're delighted that you're going to share you latest creation with us.<p>
<h2>Share My Latest Creation</h2>
app/views/creations/show.html.erb
@@ -1,3 +1,6 @@
+<% content_for :title do %>
+ <%= @creation.name %> by <%= @creation.user.name %>
+<% end %>
<% if signed_in? %>
<div class="floatRight">
app/views/home/index.html.erb
@@ -1,10 +1,12 @@
+<% content_for :title do %>
+ Welcome to the CakeSide
+<% end %>
<% content_for :script do %>
$('#s1').removeClass('hidden');
$('#s1').addClass('slide');
$('#s1').cycle({fx:'fade',speed:1500,timeout:4000});
<% end %>
-
<h1>Welcome to the CakeSide</h1>
<p><em>An online community for cake artists, enthusiasists and eaters.</em></p>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec malesuada facilisis erat, id sollicitudin leo sollicitudin in. Quisque quis elit eget neque convallis imperdiet in ut odio. Nunc vel lectus turpis, nec tincidunt ipsum. Pellentesque turpis tellus, pulvinar vehicula sodales a, sollicitudin egestas mauris. </p>
app/views/kaminari/_first_page.html.erb
@@ -0,0 +1,11 @@
+<%# Link to the "First" page
+ - available local variables
+ url: url to the first page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<span class="first">
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
+</span>
app/views/kaminari/_gap.html.erb
@@ -0,0 +1,8 @@
+<%# Non-link tag that stands for skipped pages...
+ - available local variables
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<span class="page gap"><%= raw(t 'views.pagination.truncate') %></span>
app/views/kaminari/_last_page.html.erb
@@ -0,0 +1,11 @@
+<%# Link to the "Last" page
+ - available local variables
+ url: url to the last page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<span class="last">
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
+</span>
app/views/kaminari/_next_page.html.erb
@@ -0,0 +1,11 @@
+<%# Link to the "Next" page
+ - available local variables
+ url: url to the next page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<span class="next">
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
+</span>
app/views/kaminari/_page.html.erb
@@ -0,0 +1,12 @@
+<%# Link showing page number
+ - available local variables
+ page: a page object for "this" page
+ url: url to this page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<span class="page<%= ' current' if page.current? %>">
+ <%= link_to_unless page.current?, page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
+</span>
app/views/kaminari/_paginator.html.erb
@@ -0,0 +1,23 @@
+<%# The container tag
+ - available local variables
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+ paginator: the paginator that renders the pagination tags inside
+-%>
+<%= paginator.render do -%>
+ <nav class="pagination">
+ <%= first_page_tag unless current_page.first? %>
+ <%= prev_page_tag unless current_page.first? %>
+ <% each_page do |page| -%>
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
+ <%= page_tag page %>
+ <% elsif !page.was_truncated? -%>
+ <%= gap_tag %>
+ <% end -%>
+ <% end -%>
+ <%= next_page_tag unless current_page.last? %>
+ <%= last_page_tag unless current_page.last? %>
+ </nav>
+<% end -%>
app/views/kaminari/_prev_page.html.erb
@@ -0,0 +1,11 @@
+<%# Link to the "Previous" page
+ - available local variables
+ url: url to the previous page
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<span class="prev">
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
+</span>
app/views/profiles/index.html.erb
@@ -1,3 +1,6 @@
+<% content_for :title do %>
+ All <%= @profiles.length %> profiles
+<% end %>
<h1>All <%= @profiles.length %> profiles</h1>
@@ -22,3 +25,5 @@
</tbody>
</table>
+<hr class="clear" />
+<p> <%= paginate @profiles %> </p>
app/views/profiles/show.html.erb
@@ -1,3 +1,7 @@
+<% content_for :title do %>
+ <%= @profile.name %>
+<% end %>
+
<%= image_tag avatar_url(@profile) + '&s=200', :class => ['photo', 'floatLeft'] %>
<h1><%= @profile.name %></h1>
<p><em>A member since <%= @profile.created_at %>, with <%= @profile.creations.length %> creations.</em></p>
app/views/registrations/edit.html.erb
@@ -1,3 +1,7 @@
+<% content_for :title do %>
+ Update My Account
+<% end %>
+
<%= link_to "my other authentications", authentications_path, :class => 'floatRight' %>
<h1>Update My Account</h1>
<p>
app/views/registrations/new.html.erb
@@ -1,3 +1,7 @@
+<% content_for :title do %>
+ C'mon In...
+<% end %>
+
<h1>C'mon In... </h1>
<p>"You don't make friends with salad" - Homer Simpson<p>
<p>Already have an account. Then <%= link_to "sign in", new_user_session_path %>.</p>
app/views/search/index.html.erb
@@ -1,3 +1,7 @@
+<% content_for :title do %>
+ Search Results for <%= @search %>
+<% end %>
+
<h1>Search Results for <em><%= @search %></em></h1>
<p><em>What time is it? Nana, nana, naaaaana caake time!</em></p>
@@ -16,3 +20,6 @@
<p><%= creation.short_story %> <%= link_to 'more', creation %></p>
</div>
<% end %>
+
+<hr class="clear" />
+<p> <%= paginate @profiles %> </p>
config/initializers/kaminari_config.rb
@@ -0,0 +1,8 @@
+Kaminari.configure do |config|
+ # config.default_per_page = 25
+ # config.window = 4
+ # config.outer_window = 0
+ # config.left = 0
+ # config.right = 0
+ # config.param_name = :page
+end
spec/controllers/creations_controller_spec.rb
@@ -21,7 +21,7 @@ describe CreationsController do
describe "GET index" do
it "assigns all creations as @creations" do
- Creation.stub(:all) { [mock_creation] }
+ Creation.stub(:page) { [mock_creation] }
get :index
assigns(:creations).should eq([mock_creation])
end
spec/support/kaminari.rb
@@ -0,0 +1,4 @@
+module Kaminari::ActionViewExtension::InstanceMethods
+ def paginate(scope, options = {}, &block)
+ end
+end
Gemfile
@@ -18,6 +18,7 @@ gem 'bcrypt-ruby'
gem 'json'
gem 'thinking-sphinx'
gem 'fog'
+gem 'kaminari'
# Use unicorn as the web server
# gem 'unicorn'
Gemfile.lock
@@ -68,6 +68,8 @@ GEM
railties (~> 3.0)
thor (~> 0.14)
json (1.5.3)
+ kaminari (0.12.4)
+ rails (>= 3.0.0)
launchy (0.4.0)
configuration (>= 0.0.5)
rake (>= 0.8.1)
@@ -202,6 +204,7 @@ DEPENDENCIES
heroku
jquery-rails
json
+ kaminari
omniauth
pg
rails