Update README
This commit is contained in:
parent
77cefa6212
commit
39324dfd5e
26
README.md
26
README.md
|
@ -19,19 +19,13 @@ In your Gemfile:
|
||||||
For Rails 3:
|
For Rails 3:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
gem "ransack" # Last officially released gem (Rails 3)
|
gem "ransack"
|
||||||
```
|
```
|
||||||
|
|
||||||
Or if you want to use the bleeding edge (Rails 3):
|
Or if you want to use the bleeding edge (Rails 3 and 4):
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
gem "ransack", :git => "git://github.com/ernie/ransack.git" # Track git repo (Rails 3)
|
gem "ransack", github: "ernie/ransack" # Track git repo
|
||||||
```
|
|
||||||
|
|
||||||
For Rails 4, specify the "rails-4" branch:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
gem "ransack", github: "ernie/ransack", branch: "rails-4" # Use rails 4 branch
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -54,12 +48,12 @@ If you're coming from MetaSearch, things to note:
|
||||||
is passed to it.
|
is passed to it.
|
||||||
3. Common ActiveRecord::Relation methods are no longer delegated by the search object.
|
3. Common ActiveRecord::Relation methods are no longer delegated by the search object.
|
||||||
Instead, you will get your search results (an ActiveRecord::Relation in the case of
|
Instead, you will get your search results (an ActiveRecord::Relation in the case of
|
||||||
the ActiveRecord adapter) via a call to `Search#result`. If passed `:distinct => true`,
|
the ActiveRecord adapter) via a call to `Search#result`. If passed `distinct: true`,
|
||||||
`result` will generate a `SELECT DISTINCT` to avoid returning duplicate rows, even if
|
`result` will generate a `SELECT DISTINCT` to avoid returning duplicate rows, even if
|
||||||
conditions on a join would otherwise result in some.
|
conditions on a join would otherwise result in some.
|
||||||
|
|
||||||
Please note that for many databases, a sort on an associated table's columns will
|
Please note that for many databases, a sort on an associated table's columns will
|
||||||
result in invalid SQL with `:distinct => true` -- in those cases, you're on your own,
|
result in invalid SQL with `distinct: true` -- in those cases, you're on your own,
|
||||||
and will need to modify the result as needed to allow these queries to work. Thankfully,
|
and will need to modify the result as needed to allow these queries to work. Thankfully,
|
||||||
9 times out of 10, sort against the search's base is sufficient, though, as that's
|
9 times out of 10, sort against the search's base is sufficient, though, as that's
|
||||||
generally what's being displayed on your results page.
|
generally what's being displayed on your results page.
|
||||||
|
@ -69,7 +63,7 @@ In your controller:
|
||||||
```ruby
|
```ruby
|
||||||
def index
|
def index
|
||||||
@q = Person.search(params[:q])
|
@q = Person.search(params[:q])
|
||||||
@people = @q.result(:distinct => true)
|
@people = @q.result(distinct: true)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -101,7 +95,7 @@ This means you'll need to tweak your routes...
|
||||||
```ruby
|
```ruby
|
||||||
resources :people do
|
resources :people do
|
||||||
collection do
|
collection do
|
||||||
match 'search' => 'people#search', :via => [:get, :post], :as => :search
|
match 'search' => 'people#search', via: [:get, :post], as: :search
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
@ -118,8 +112,8 @@ end
|
||||||
... and update your `search_form_for` line in the view ...
|
... and update your `search_form_for` line in the view ...
|
||||||
|
|
||||||
```erb
|
```erb
|
||||||
<%= search_form_for @q, :url => search_people_path,
|
<%= search_form_for @q, url: search_people_path,
|
||||||
:html => {:method => :post} do |f| %>
|
html: { method: :post } do |f| %>
|
||||||
```
|
```
|
||||||
|
|
||||||
Once you've done so, you can make use of the helpers in Ransack::Helpers::FormBuilder to
|
Once you've done so, you can make use of the helpers in Ransack::Helpers::FormBuilder to
|
||||||
|
@ -159,7 +153,7 @@ end
|
||||||
class SupervisorsController < ApplicationController
|
class SupervisorsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@search = Supervisor.search(params[:q])
|
@search = Supervisor.search(params[:q])
|
||||||
@supervisors = @search.result(:distinct => true)
|
@supervisors = @search.result(distinct: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue