Skip to content

Commit

Permalink
Updates to fix sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernie Miller committed Jun 11, 2011
1 parent f55f5f8 commit 5297233
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'http://rubygems.org'

gem 'rake', '~> 0.8.7'
gem 'rails', '3.1.0.rc3'
gem 'rails', '3.1.0.rc4'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
Expand Down
54 changes: 28 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.0.rc3)
actionpack (= 3.1.0.rc3)
actionmailer (3.1.0.rc4)
actionpack (= 3.1.0.rc4)
mail (~> 2.3.0)
actionpack (3.1.0.rc3)
activemodel (= 3.1.0.rc3)
activesupport (= 3.1.0.rc3)
actionpack (3.1.0.rc4)
activemodel (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
Expand All @@ -16,20 +16,20 @@ GEM
rack-test (~> 0.6.0)
sprockets (~> 2.0.0.beta.10)
tzinfo (~> 0.3.27)
activemodel (3.1.0.rc3)
activesupport (= 3.1.0.rc3)
activemodel (3.1.0.rc4)
activesupport (= 3.1.0.rc4)
bcrypt-ruby (~> 2.1.4)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.0.rc3)
activemodel (= 3.1.0.rc3)
activesupport (= 3.1.0.rc3)
activerecord (3.1.0.rc4)
activemodel (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
arel (~> 2.1.1)
tzinfo (~> 0.3.27)
activeresource (3.1.0.rc3)
activemodel (= 3.1.0.rc3)
activesupport (= 3.1.0.rc3)
activesupport (3.1.0.rc3)
activeresource (3.1.0.rc4)
activemodel (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
activesupport (3.1.0.rc4)
multi_json (~> 1.0)
ansi (1.2.5)
arel (2.1.1)
Expand Down Expand Up @@ -67,25 +67,27 @@ GEM
rack
rack-test (0.6.0)
rack (>= 1.0)
rails (3.1.0.rc3)
actionmailer (= 3.1.0.rc3)
actionpack (= 3.1.0.rc3)
activerecord (= 3.1.0.rc3)
activeresource (= 3.1.0.rc3)
activesupport (= 3.1.0.rc3)
rails (3.1.0.rc4)
actionmailer (= 3.1.0.rc4)
actionpack (= 3.1.0.rc4)
activerecord (= 3.1.0.rc4)
activeresource (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
bundler (~> 1.0)
railties (= 3.1.0.rc3)
railties (3.1.0.rc3)
actionpack (= 3.1.0.rc3)
activesupport (= 3.1.0.rc3)
railties (= 3.1.0.rc4)
railties (3.1.0.rc4)
actionpack (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.8.7)
ransack (0.4.2)
ransack (0.5.1)
actionpack (~> 3.0)
activerecord (~> 3.0)
activesupport (~> 3.0)
rdoc (3.6.1)
sass (3.1.2)
sass-rails (3.1.0.rc.2)
actionpack (~> 3.1.0.rc1)
Expand Down Expand Up @@ -117,7 +119,7 @@ DEPENDENCIES
jquery-rails
machinist
pg
rails (= 3.1.0.rc3)
rails (= 3.1.0.rc4)
rake (~> 0.8.7)
ransack
sass-rails (~> 3.1.0.rc)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def search
def configure_search
@search = User.search(params[:q])
@search.build_grouping unless @search.groupings.any?
@users = @search.result(distinct: true)
@users = params[:distinct].to_i.zero? ? @search.result : @search.result(distinct: true)
end

end
4 changes: 4 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Post < ActiveRecord::Base

validates_presence_of :user

ransacker :title_diddly do |parent|
Arel::Nodes::InfixOperation.new('||', parent.table[:title], '-diddly')
end

def tag_names=(names)
self.tags = names.split(/,\s*/).map do |name|
Tag.find_or_create_by_name(name)
Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ class User < ActiveRecord::Base
has_many :posts
has_many :comments
has_and_belongs_to_many :roles

ransacker :full_name do |parent|
Arel::Nodes::InfixOperation.new('||',
Arel::Nodes::InfixOperation.new('||', parent.table[:first_name], ' '),
parent.table[:last_name])
end
end
2 changes: 1 addition & 1 deletion app/views/users/_sort_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span class="fields" data-object-name="<%= f.object_name %>">
<%= f.sort_select associations: %w(posts comments) %>
<%= f.sort_select %>
<%= button_to_remove_fields "remove", f %>
</span>
24 changes: 16 additions & 8 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
<%= search_form_for @search, url: search_users_path, html: {method: :post} do |f| %>
<% setup_search_form f %>

<%= f.sort_fields do |s| %>
<%= render 'sort_fields', f: s %>
<% end %>
<%= button_to_add_fields "Add Sort", f, :sort %>
<fieldset>
<legend>Sorting</legend>
<%= f.sort_fields do |s| %>
<%= render 'sort_fields', f: s %>
<% end %>
<%= button_to_add_fields "Add Sort", f, :sort %>
</fieldset>

<%= f.grouping_fields do |g| %>
<%= render 'grouping_fields', f: g %>
<% end %>
<%= button_to_add_fields "Add Condition Group", f, :grouping %>
<fieldset>
<legend>Condition Groups</legend>
<%= f.grouping_fields do |g| %>
<%= render 'grouping_fields', f: g %>
<% end %>
<%= button_to_add_fields "Add Condition Group", f, :grouping %>
</fieldset>

<%= label_tag :distinct, 'Return distinct records?' %>
<%= check_box_tag :distinct, '1', params[:distinct].to_i == 1 %>
<%= f.submit %>
<% end %>

Expand Down

0 comments on commit 5297233

Please sign in to comment.