From e7aff87c658bcb62cddd43278c5f6d71c22b61e9 Mon Sep 17 00:00:00 2001 From: albert Date: Tue, 19 Feb 2013 13:30:55 -0500 Subject: [PATCH] fix for pool selection --- app/assets/javascripts/pools.js | 2 +- app/controllers/pools_controller.rb | 2 +- app/models/pool.rb | 3 ++- app/models/tag.rb | 4 ++-- app/views/pool_elements/_new.html.erb | 5 ----- app/views/pools/index.html.erb | 2 +- app/views/pools/show.html.erb | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/pools.js b/app/assets/javascripts/pools.js index 125bf3d44..345532c84 100644 --- a/app/assets/javascripts/pools.js +++ b/app/assets/javascripts/pools.js @@ -19,7 +19,7 @@ $.getJSON( "/pools.json?search[name_matches]=" + req.term, function(data) { - resp(data.map(function(x) {return x.name;})); + resp(data.map(function(x) {return x.name.replace(/_/g, " ");})); } ); }, diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index f13245353..086e9a30d 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -16,7 +16,7 @@ class PoolsController < ApplicationController def index @search = Pool.active.search(params[:search]) - @pools = @search.paginate(params[:page]).order("name") + @pools = @search.paginate(params[:page]).order("updated_at desc") respond_with(@pools) end diff --git a/app/models/pool.rb b/app/models/pool.rb index d0242149f..eab9135b4 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -25,6 +25,7 @@ class Pool < ActiveRecord::Base return q if params.blank? if params[:name_matches].present? + params[:name_matches] = params[:name_matches].tr(" ", "_") params[:name_matches] += "*" unless params[:name_matches] =~ /\*/ q = q.where("name ilike ? escape E'\\\\'", params[:name_matches].to_escaped_for_sql_like) end @@ -66,7 +67,7 @@ class Pool < ActiveRecord::Base end def self.options - select_all_sql("SELECT id, name FROM pools WHERE is_active = true AND is_deleted = false ORDER BY name LIMIT 100").map {|x| [x["name"], x["id"]]} + select_all_sql("SELECT id, name FROM pools WHERE is_active = true AND is_deleted = false ORDER BY name LIMIT 100").map {|x| [x["name"].tr("_", " "), x["id"]]} end def self.create_anonymous diff --git a/app/models/tag.rb b/app/models/tag.rb index 4386c6d85..0bcca6419 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -402,10 +402,10 @@ class Tag < ActiveRecord::Base case params[:sort].present? when "count" - q = q.order("post_count") + q = q.order("post_count desc") when "date" - q = q.order("created_at") + q = q.order("created_at desc") else q = q.order("name") diff --git a/app/views/pool_elements/_new.html.erb b/app/views/pool_elements/_new.html.erb index 92ec6eba2..14c93cfca 100644 --- a/app/views/pool_elements/_new.html.erb +++ b/app/views/pool_elements/_new.html.erb @@ -3,11 +3,6 @@ <%= form_tag(pool_element_path, :class => "simple_form") do %> <%= hidden_field_tag "post_id", @post.id %> -
- - <%= select_tag "pool_id", options_for_select([["", ""]] + Pool.options) %> -
-
<%= text_field_tag "pool_name", "", :size => 20 %> diff --git a/app/views/pools/index.html.erb b/app/views/pools/index.html.erb index b63d4fb55..04bd49416 100644 --- a/app/views/pools/index.html.erb +++ b/app/views/pools/index.html.erb @@ -15,7 +15,7 @@ - <%= link_to h(pool.name), pool_path(pool) %> + <%= link_to h(pool.pretty_name), pool_path(pool) %> <%= link_to h(pool.creator.name), user_path(pool.creator) %> diff --git a/app/views/pools/show.html.erb b/app/views/pools/show.html.erb index a5b53d820..6560dc159 100644 --- a/app/views/pools/show.html.erb +++ b/app/views/pools/show.html.erb @@ -1,6 +1,6 @@
-

Pool: <%= @pool.name %>

+

Pool: <%= @pool.pretty_name %>

<%= format_text(@pool.description) %>