あいまい検索とは、「用語の一部の一致」を探して、一部でもマッチングするものを抽出する検索のこと。 「鈴木」で検索したら、「鈴木美保」、「鈴木亜美」、「鈴木えみ」を検索するようなイメージですね。 Railsのあいまい検索の書き方は、以下の様な感じです。 where("カラム名 like '%検索テキスト%'")コントローラーは以下のようにコーディングします。 bloggers_controller.rb def find @datas = [] if request.post? then fstr = params[:fstr] @datas = Blogger.where("name like '%" + fstr + "%'") end end ここでのポイントは、 if request.post? then @word = params[:fstr] fstr = params[:fs
![Railsであいまい検索(LIKE)やAND検索を行う - 感謝のプログラミング](https://cdn-ak-scissors.b.st-hatena.com/image/square/f3fecb92e2fe553836e8c5c4b8dc3ed15fe5c957/height=288;version=1;width=512/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fs%2Fsho322%2F20140413%2F20140413133350.png)