Permalink
Browse files

Added search, pagination, dream count and drop-down bootstrap menu

  • Loading branch information...
1 parent 88cbb9f commit 1dcf630a9b63686661040ad7e7aca4ee92a0cc00 @cpursley committed Nov 24, 2012
View
@@ -2,6 +2,8 @@ source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'bootstrap-sass'
+gem 'will_paginate', '3.0.3'
+gem 'bootstrap-will_paginate', '0.0.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
@@ -31,6 +31,8 @@ GEM
arel (3.0.2)
bcrypt-ruby (3.0.1)
bootstrap-sass (2.0.4.0)
+ bootstrap-will_paginate (0.0.6)
+ will_paginate
builder (3.0.4)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
@@ -108,16 +110,19 @@ GEM
multi_json (~> 1.0, >= 1.0.2)
warden (1.2.1)
rack (>= 1.0)
+ will_paginate (3.0.3)
PLATFORMS
ruby
DEPENDENCIES
bootstrap-sass
+ bootstrap-will_paginate (= 0.0.6)
coffee-rails (~> 3.2.1)
devise
jquery-rails
rails (= 3.2.8)
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)
+ will_paginate (= 3.0.3)
@@ -12,4 +12,6 @@
//
//= require jquery
//= require jquery_ujs
+//= require bootstrap
//= require_tree .
+
@@ -2,7 +2,16 @@ class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate_user!, :except => [:index, :show, :about]
+
+ before_filter :count_dreams
def about
end
+
+ protected
+ def count_dreams
+ @num_private = Dream.where(:state => '0').count.to_s
+ @num_published = Dream.where(:state => '1').count.to_s
+ @num_all_my = Dream.where(:state => ['0', '1']).count.to_s
+ end
end
@@ -5,7 +5,7 @@ class DreamsController < ApplicationController
# GET /dreams
# GET /dreams.json
def index
- @dreams = Dream.where(:state => '1') # published view
+ @dreams = Dream.where(:state => '1').search(params[:search]).order('accepted desc').paginate(:page => params[:page], :per_page => 10) # published view
respond_to do |format|
format.html # index.html.erb
View
@@ -23,6 +23,14 @@ def avg_rating
@avg ? @avg : 0
end
+def self.search(search)
+ if search
+ where('title LIKE ? or teaser LIKE ?', "%#{search}%", "%#{search}%")
+ else
+ scoped
+ end
+end
+
protected
def record_not_found
flash[:error] = 'The dream you requested could not be found.'
@@ -10,8 +10,9 @@
<div class = "teaser"><%= dream.teaser %></div>
</dream>
<% end %>
+
+ <%= will_paginate @dreams %>
+
</section>
<br />
-
-<%= link_to 'New Dream', new_dream_path %>
@@ -1,21 +1,36 @@
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
- <%= link_to "Lucidly: A dream journal", '/', id: "logo" %>
+ <%= link_to "Lucidly", '/', id: "logo" %>
<nav>
<ul class="nav pull-right">
+ <form class="navbar-search">
+ <%= form_tag all_dreams_path, :method => 'get' do %>
+ <%= text_field_tag :search, params[:search] %>
+ <% end %>
+ </form>
<li><%= link_to "Dreams", root_path %></li>
- <li><%= link_to "My Dreams", mydreams_dreams_path %></li>
- <% if user_signed_in? %>
- <li><%= link_to "My Profile", edit_user_registration_path %></li>
- <li><%= link_to "Sign out", destroy_user_session_path %></li>
- <% else %>
- <li><%= link_to "About", about_dreams_path %></li>
- <li><%= link_to "Sign up", new_user_registration_path %></li>
- <li><%= link_to "Sign in", new_user_session_path %></li>
+ <% if user_signed_in? %>
+ <li><%= link_to "My Dreams [" + @num_all_my + "]", mydreams_dreams_path %></li>
+ <li id="fat-menu" class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= current_user.email %> <b class="caret"></b></a>
+
+
+ <ul class="dropdown-menu">
+ <li><%= link_to "Profile", edit_user_registration_path %></li>
+ <li class="divider"></li>
+ <li><%= link_to "Sign out", destroy_user_session_path, method: "delete" %></li>
+ <% else %>
+ <li><%= link_to "About", about_dreams_path %></li>
+ <li><%= link_to "Sign up", new_user_registration_path %></li>
+ <li><%= link_to "Sign in", new_user_session_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
-</header>
+</header>
+
+
+
+ <% #submit_tag "Search Dreams", :name => nil, :class => "search-query" %>
+

0 comments on commit 1dcf630

Please sign in to comment.