(Rails3.2.13)
前にやったMetaSearchのgithubをよく見たら開発が止まっているようで他になにかないかと探してたら発見した。
MetaSearch の後継らしい。
とりあえずやってみる
rails new app -T --skip-bundle : cd app/
Gemfile
gem "ransack"
shell
$ bundle install $ rails g scaffold Person name articles_title : $ rake db:migrate
app/controllers/people_controller.rb
def index def index @q = Person.search(params[:q]) @people = @q.result(distinct: true)
app/views/people/index.html.erb
<h1>Listing people</h1> <%= search_form_for @q do |f| %> <div> <%= f.label "Name" %> <%= f.text_field :name_eq %> </div> <div> <%= f.label "Articles Title" %> <%= f.text_field :articles_title_cont %> </div> <div> <%= f.submit %> </div> <% end %>
Shell
$ rails s