Update README

This commit is contained in:
jonatack 2013-08-06 19:47:59 +02:00
parent 77cefa6212
commit 39324dfd5e
1 changed files with 10 additions and 16 deletions

View File

@ -19,19 +19,13 @@ In your Gemfile:
For Rails 3:
```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
gem "ransack", :git => "git://github.com/ernie/ransack.git" # Track git repo (Rails 3)
```
For Rails 4, specify the "rails-4" branch:
```ruby
gem "ransack", github: "ernie/ransack", branch: "rails-4" # Use rails 4 branch
gem "ransack", github: "ernie/ransack" # Track git repo
```
## Usage
@ -54,12 +48,12 @@ If you're coming from MetaSearch, things to note:
is passed to it.
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
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
conditions on a join would otherwise result in some.
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,
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.
@ -69,7 +63,7 @@ In your controller:
```ruby
def index
@q = Person.search(params[:q])
@people = @q.result(:distinct => true)
@people = @q.result(distinct: true)
end
```
@ -101,7 +95,7 @@ This means you'll need to tweak your routes...
```ruby
resources :people do
collection do
match 'search' => 'people#search', :via => [:get, :post], :as => :search
match 'search' => 'people#search', via: [:get, :post], as: :search
end
end
```
@ -118,8 +112,8 @@ end
... and update your `search_form_for` line in the view ...
```erb
<%= search_form_for @q, :url => search_people_path,
:html => {:method => :post} do |f| %>
<%= search_form_for @q, url: search_people_path,
html: { method: :post } do |f| %>
```
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
def index
@search = Supervisor.search(params[:q])
@supervisors = @search.result(:distinct => true)
@supervisors = @search.result(distinct: true)
end
end
```