enable syntax highlighting on README
This commit is contained in:
parent
e3914b814f
commit
1b9bbb8dcf
25
README.md
25
README.md
|
@ -2,7 +2,7 @@
|
|||
|
||||
[![Build Status](https://travis-ci.org/ernie/ransack.png?branch=master)](https://travis-ci.org/ernie/ransack)
|
||||
|
||||
Ransack is a rewrite of [MetaSearch](http://metautonomo.us/projects/metasearch). While it
|
||||
Ransack is a rewrite of [MetaSearch](https://github.com/ernie/meta_search). While it
|
||||
supports many of the same features as MetaSearch, its underlying implementation differs
|
||||
greatly from MetaSearch, and _backwards compatibility is not a design goal._
|
||||
|
||||
|
@ -10,18 +10,21 @@ Ransack enables the creation of both simple and [advanced](http://ransack-demo.h
|
|||
search forms against your application's models. If you're looking for something that
|
||||
simplifies query generation at the model or controller layer, you're probably not looking
|
||||
for Ransack (or MetaSearch, for that matter). Try
|
||||
[Squeel](http://metautonomo.us/projects/squeel) instead.
|
||||
[Squeel](https://github.com/ernie/squeel) instead.
|
||||
|
||||
## Getting started
|
||||
|
||||
In your Gemfile:
|
||||
|
||||
```ruby
|
||||
gem "ransack" # Last officially released gem
|
||||
```
|
||||
|
||||
Or if you want to use the bleeding edge:
|
||||
|
||||
```ruby
|
||||
gem "ransack", :git => "git://github.com/ernie/ransack.git" # Track git repo
|
||||
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -55,13 +58,16 @@ If you're coming from MetaSearch, things to note:
|
|||
|
||||
In your controller:
|
||||
|
||||
```ruby
|
||||
def index
|
||||
@q = Person.search(params[:q])
|
||||
@people = @q.result(:distinct => true)
|
||||
end
|
||||
```
|
||||
|
||||
In your view:
|
||||
|
||||
```erb
|
||||
<%= search_form_for @q do |f| %>
|
||||
<%= f.label :name_cont %>
|
||||
<%= f.text_field :name_cont %>
|
||||
|
@ -69,6 +75,7 @@ In your view:
|
|||
<%= f.text_field :articles_title_start %>
|
||||
<%= f.submit %>
|
||||
<% end %>
|
||||
```
|
||||
|
||||
`cont` (contains) and `start` (starts with) are just two of the available search predicates.
|
||||
See [Constants](https://github.com/ernie/ransack/blob/master/lib/ransack/constants.rb) for a full list and the [wiki](https://github.com/ernie/ransack/wiki/Basic-Searching) for more description.
|
||||
|
@ -83,23 +90,29 @@ parameter string will typically force you to use the HTTP POST method instead of
|
|||
|
||||
This means you'll need to tweak your routes...
|
||||
|
||||
```ruby
|
||||
resources :people do
|
||||
collection do
|
||||
match 'search' => 'people#search', :via => [:get, :post], :as => :search
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
... and add another controller action ...
|
||||
|
||||
```ruby
|
||||
def search
|
||||
index
|
||||
render :index
|
||||
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| %>
|
||||
```
|
||||
|
||||
Once you've done so, you can make use of the helpers in Ransack::Helpers::FormBuilder to
|
||||
construct much more complex search forms, such as the one on the
|
||||
|
@ -111,6 +124,7 @@ You can easily use Ransack to search in associated objects.
|
|||
|
||||
Given you have these associations ...
|
||||
|
||||
```ruby
|
||||
class Employee < ActiveRecord::Base
|
||||
belongs_to :supervisor
|
||||
|
||||
|
@ -129,18 +143,22 @@ Given you have these associations ...
|
|||
|
||||
# has attribute last_name:string
|
||||
end
|
||||
```
|
||||
|
||||
... and a controller ...
|
||||
|
||||
```ruby
|
||||
class SupervisorsController < ApplicationController
|
||||
def index
|
||||
@search = Supervisor.search(params[:q])
|
||||
@supervisors = @search.result(:distinct => true)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
... you might set up your form like this ...
|
||||
|
||||
```erb
|
||||
<%= search_form_for @search do |f| %>
|
||||
<%= f.label :last_name_cont %>
|
||||
<%= f.text_field :last_name_cont %>
|
||||
|
@ -153,6 +171,7 @@ Given you have these associations ...
|
|||
|
||||
<%= f.submit "search" %>
|
||||
<% end %>
|
||||
```
|
||||
|
||||
|
||||
## Contributions
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
fr:
|
||||
ransack:
|
||||
search: "recherche"
|
||||
predicate: "prédicat"
|
||||
and: "et"
|
||||
or: "ou"
|
||||
any: "au moins un"
|
||||
all: "tous"
|
||||
combinator: "combinateur"
|
||||
attribute: "attribut"
|
||||
value: "valeur"
|
||||
condition: "condition"
|
||||
sort: "tri"
|
||||
asc: "ascendant"
|
||||
desc: "descendant"
|
||||
predicates:
|
||||
eq: "égal à"
|
||||
eq_any: "égal à au moins un"
|
||||
eq_all: "égal à tous"
|
||||
not_eq: "différent de"
|
||||
not_eq_any: "différent d'au moins un"
|
||||
not_eq_all: "différent de tous"
|
||||
matches: "correspond à"
|
||||
matches_any: "correspond à au moins un"
|
||||
matches_all: "correspond à tous"
|
||||
does_not_match: "ne correspond pas à"
|
||||
does_not_match_any: "ne correspond pas à au moins un"
|
||||
does_not_match_all: "ne correspond à aucun"
|
||||
lt: "inférieur à"
|
||||
lt_any: "inférieur à au moins un"
|
||||
lt_all: "inférieur à tous"
|
||||
lteq: "inférieur ou égal à"
|
||||
lteq_any: "inférieur ou égal à au moins un"
|
||||
lteq_all: "inférieur ou égal à tous"
|
||||
gt: "supérieur à"
|
||||
gt_any: "supérieur à au moins un"
|
||||
gt_all: "supérieur à tous"
|
||||
gteq: "supérieur ou égal à"
|
||||
gteq_any: "supérieur ou égal à au moins un"
|
||||
gteq_all: "supérieur ou égal à tous"
|
||||
in: "inclus dans"
|
||||
in_any: "inclus dans au moins un"
|
||||
in_all: "inclus dans tous"
|
||||
not_in: "non inclus dans"
|
||||
not_in_any: "non inclus dans au moins un"
|
||||
not_in_all: "non inclus dans tous"
|
||||
cont: "contient"
|
||||
cont_any: "contient au moins un"
|
||||
cont_all: "contient tous"
|
||||
not_cont: "ne contient pas"
|
||||
not_cont_any: "ne contient pas au moins un"
|
||||
not_cont_all: "ne contient pas tous"
|
||||
start: "commence par"
|
||||
start_any: "commence par au moins un"
|
||||
start_all: "commence par tous"
|
||||
not_start: "ne commence pas par"
|
||||
not_start_any: "ne commence pas par au moins un"
|
||||
not_start_all: "ne commence pas par tous"
|
||||
end: "finit par"
|
||||
end_any: "finit par au moins un"
|
||||
end_all: "finit par tous"
|
||||
not_end: "ne finit pas par"
|
||||
not_end_any: "ne finit pas par au moins un"
|
||||
not_end_all: "ne finit pas par tous"
|
||||
'true': "est vrai"
|
||||
'false': "est faux"
|
||||
present: "est présent"
|
||||
blank: "est blanc"
|
||||
'null': "est null"
|
||||
not_null: "n'est pas null"
|
Loading…
Reference in New Issue