ransack_advanced_search 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88442c12af23f8798db4d31ab864106694779952
4
- data.tar.gz: d230a564262b94f69d58ba9b410d9ed53a1bf8c0
3
+ metadata.gz: 82bba0e8cbaf970ff9d233609ac59bf155bfa084
4
+ data.tar.gz: 36b15a6a0de51c434d5d10018378aeeb9560bf74
5
5
  SHA512:
6
- metadata.gz: 41868575d4ab5ab953642a5df1c54707f6596e6771735b7cdb709f1f4729a77de438617150e34e166ee884433219446ba34886600d57934086bfad13ec52abe3
7
- data.tar.gz: 31ceeeabd6c1046ba58627bc6fb37fb23a16eb26229fd625a98a508ae705c125cdf4668adbf6f1714fcd56c9714f14622c9a0a41e7625e547b46353a487bb840
6
+ metadata.gz: 7a1bdb8394ed1c8c0a1bd121915f0aa3f0b7b8a193be7f15fe7846c77ceaf515ea728d5354100b97a0cd001a2f3fdb9ad29989fdc625f3ce7f07bffbb5650cae
7
+ data.tar.gz: 05870bf3a5d6c051f8b42f0c87552539aeeb54ad722d6ba8f2386c8bc545f4390983937d27c7c9d130e0320dfee269f8ed91312e633f6676d7b693b2fc8a74c0
data/README.md CHANGED
@@ -45,15 +45,38 @@ First, in your controller action that you will use for search, include the follo
45
45
  # GET /your_models.json
46
46
  # POST /your_models/advanced_search
47
47
  def index
48
- # The ransack search must be in the @search instance variable, because the advanced search will use it to build the search form
48
+ # The ransack search must be in the @search instance variable, because the advanced search will use it to build the search form. You must provide associations you will use in the includes method.
49
49
  @search = YourModel.search(params[:q])
50
- @results = @search.result()
50
+ @results = @search.result().includes(:association1, :association2)
51
51
  # or, if the above doesn't work
52
52
  @search = YourModel.ransack(params[:q])
53
- @results = @search.result()
53
+ @results = @search.result(:association1, :association2)
54
54
  end
55
55
  ```
56
56
 
57
+ To use the Advanced Search with associtions you must provide a method in your model to tell what are the associations for that model
58
+ ```ruby
59
+ class YourModel < ActiveRecord::Base
60
+ # Associations to be included in the search attributes
61
+ def self.ransackable_associations(*)
62
+ %w( association1 association2 )
63
+ end
64
+ end
65
+ ```
66
+
67
+ By default ransack will provide all your model fields to the avaliable field to search. You can restrict what fields will be included in the Advanced Search by defining it in your model, like this:
68
+ ```ruby
69
+ class YourModel < ActiveRecord::Base
70
+ # Fields that will be included in ransack advanced search
71
+ def self.ransackable_attributes(*)
72
+ %w( name description other_fields_names ) + _ransackers.keys
73
+ end
74
+ end
75
+ ```
76
+
77
+ This rule applies to each model included in the search, even in the associations you can restrict fields to search.
78
+
79
+
57
80
  Now, we have to create a POST route to this action, in your `config/routes.rb` provide a POST route to this controller/action:
58
81
 
59
82
  ```ruby
@@ -65,7 +88,7 @@ resources :your_models do
65
88
  end
66
89
  ```
67
90
 
68
- We have a ransack search well configured, from this step we will include the Advanced Search query mode in our views
91
+ We have a ransack search well configured, from this step we will include the Advanced Search query mode in our views.
69
92
 
70
93
  In your application layout `app/views/layouts/application.erb`, include a yield in the head section to load ransack advanced search dependencies:
71
94
  ```html
@@ -83,7 +106,7 @@ In the view that you want the advanced search views, insert the following:
83
106
  ```ruby
84
107
  <%= render partial: 'ransack_advanced_search/advanced_search',
85
108
  locals: {
86
- search_url: advanced_search_your_models_path, # POST route whe created above
109
+ search_url: advanced_search_your_models_path, # POST route we created above
87
110
  redirect_path: your_models_path # GET redirect path, to return after some actions
88
111
  }
89
112
  %>
@@ -134,9 +157,12 @@ Table 'calendario_development.saved_searchs' doesn't exist
134
157
  ```
135
158
  To avoid this you will have to include an irregular inflection:
136
159
  ```ruby
137
- inlfect.irregular 'saved_search', 'saved_searches'
160
+ inflect.irregular 'saved_search', 'saved_searches'
138
161
  ```
139
162
 
163
+ ## i18n Support
164
+
165
+ This gem was built using i18n translation supports, and has bult-in support for English (en) and Brazilian Portuguese (pt-BR). If you want to translate to your specific language, add a new locale file in your `config/locales` and translate the values to your language. You can get one of the locales of this project to make it easier to translate to your language.
140
166
 
141
167
 
142
168
  ## Contributing
@@ -1,14 +1,14 @@
1
1
  <div class="ransack-advanced-search">
2
2
 
3
3
  <div class="row">
4
- <% if RansackAdvancedSearch.enable_saved_searches %>
5
- <div class="col-md-4">
6
- <%= render 'ransack_advanced_search/saved_searches_list' %>
7
- </div>
8
- <div class="col-md-8">
9
- <% else %>
10
- <div class="col-md-12">
11
- <% end %>
4
+ <% if RansackAdvancedSearch.enable_saved_searches %>
5
+ <div class="col-md-4">
6
+ <%= render 'ransack_advanced_search/saved_searches_list' %>
7
+ </div>
8
+ <div class="col-md-8">
9
+ <% else %>
10
+ <div class="col-md-12">
11
+ <% end %>
12
12
  <%= search_form_for(@search, url: search_url, html: { method: :post, class: 'form-vertical', role: 'form' }) do |f| %>
13
13
 
14
14
  <% setup_search_form f %>
@@ -1,3 +1,3 @@
1
1
  <%= content_tag(:span,
2
- f.attribute_select({associations: %w(posts comments)}, {class: 'form-control input-sm'}),
2
+ f.attribute_select({associations: @search.klass.ransackable_associations}, {class: 'form-control input-sm'}),
3
3
  { class: 'fields', 'data-object-name' => f.object_name }, false) %>
@@ -1,3 +1,3 @@
1
1
  module RansackAdvancedSearch
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack_advanced_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Brusius