Commit bd053ea6

mo khan <mo@mokhan.ca>
2014-10-19 15:52:12
tie current category, sort to search.
1 parent 6fda7ad
Changed files (6)
app/models/creation/repository.rb
@@ -2,7 +2,7 @@ class Creation
   include Queryable
   scope :tagged, ->(tag) { tagged_with([tag]).where('photos_count > 0') }
   scope :published, ->() { unscoped.distinct.includes(:user, :photos).joins(:photos).where('photos.image_processing' => nil) }
-  scope :search, ->(query) { where(["upper(creations.name) like :query OR upper(creations.story) like :query", { query: "%#{query.upcase}%" }]) }
+  scope :search, ->(query) { where(["UPPER(creations.name) LIKE :query OR UPPER(creations.story) LIKE :query", { query: "%#{query.upcase}%" }]) }
 
   class Repository < SimpleDelegator
     def initialize(connection = Creation)
app/views/admin/users/index.html.erb
@@ -1,12 +1,10 @@
+<%= provide(:search_path, admin_users_path) %>
 <div class="row-fluid">
   <div class="span2">
     <%= render partial: "my/shared/my_nav" %>
   </div>
   <div class="span10">
     <h1>Users <small>(<%= @users.count %>)</small></h1>
-    <%= form_tag admin_users_path, method: :get, name: "search", remote: true do %>
-      <%= text_field_tag :q, params[:q], class: "search-query", placeholder: "Search" %>
-    <% end %>
     <div id="results-container">
       <%= render partial: "index" %>
     </div>
app/views/cakes/_index.html.erb
@@ -20,5 +20,5 @@
   <% end %>
 </div>
 <div id='more-button-row' class="row-fluid">
-  <%= link_to_next_page @creations, 'More...', params: { cache: false }, remote: true, class: 'btn pull-right more-button hidden', data: { disable_with: 'loading...' } %>
+  <%= link_to_next_page @creations, 'More...', params: { cache: false, sort: params[:sort], q: params[:q] }, remote: true, class: 'btn pull-right more-button hidden', data: { disable_with: 'loading...' } %>
 </div>
app/views/cakes/index.html.erb
@@ -20,8 +20,8 @@
 <div id="bakery">
   <div class="row-fluid">
     <ul class="nav nav-tabs">
-      <li class="<%= params[:sort].blank? || params[:sort] == "newest" ? "active" : "" %>"><%= link_to "Newest", newest_cakes_path %></li>
-      <li class="<%= params[:sort] == "oldest" ? "active" : "" %>"><%= link_to "Oldest", oldest_cakes_path %></li>
+      <li class="<%= params[:sort] == "oldest" ? "active" : "" %> pull-right"><%= link_to "Oldest", url_for(params.merge(sort: "oldest")) %></li>
+      <li class="<%= params[:sort].blank? || params[:sort] == "newest" ? "active" : "" %> pull-right"><%= link_to "Newest", url_for(params.merge(sort: "newest")) %></li>
     </ul>
   </div>
   <%= render partial: 'index' %>
app/views/cakes/index.js.erb
@@ -1,3 +1,3 @@
 $('#more-button-row').remove();
 $('#pagination-row').remove();
-$('#bakery').append('<%= j render partial: 'index' %>');
+$('#bakery').append('<%= escape_javascript(render partial: 'index') %>');
config/routes.rb
@@ -18,7 +18,7 @@ Cake::Application.routes.draw do
   resources :cakes, only: [:index, :show], path: :cakes do
     resources :photos, only: [:index, :show]
     resources :favorites, :only => [:index, :create]
-    get 'page/:page', :action => :index, :on => :collection, as: :paginate
+    get 'page/:page', action: :index, on: :collection, as: :paginate
     collection do
       get :newest, action: 'index', sort: 'newest'
       get :oldest, action: 'index', sort: 'oldest'