0

タグで画像を検索するための検索フォームがあります。フォームはちょっと働き、それは/ search_resultsページにパラメータを送信しますが、それはこのように送信:acts_as_taggableで検索フォームを作成するには

search_results?utf8=✓&search=squid%2C+color&x=0&y=0 

そして、ここに私のフォームです:

<%= form_tag ("/search_results"), :method => "get", :class=>"search_form" do %> 
    <%= text_field_tag ("search"), nil, :class => 'search_input', 
    :onblur=>"if(this.value=='')this.setAttribute('class', 'search_input');", 
    :onfocus=>"this.setAttribute('class', 'search_input_clear');" 
%> 
    <%= image_submit_tag("search.png") %> 
<% end %> 

と、私のルート/コントローラ:

match "/search_results/" => "index#search_results", :via => :get, :as =>"search_results" 
class IndexController < ApplicationController 

def search_results 
    @tattoos = Tattoo.tagged_with("%#{params[:search]}%") 
end 

しかし、結果は決して得られません。

Railsのコンソールはこれを示しています

Parameters: {"utf8"=>"✓", "search"=>"color, animals", "x"=>"0", "y"=>"0"} 
    SQL (0.5ms) SHOW TABLES 
    ActsAsTaggableOn::Tag Load (0.2ms) SELECT `tags`.* FROM `tags` WHERE (name LIKE '\\%color' OR name LIKE 'animals\\%') 
    SQL (0.1ms) SELECT COUNT(*) FROM `tattoos` WHERE (1 = 0) 
    Tattoo Load (0.3ms) SELECT `tattoos`.* FROM `tattoos` WHERE (1 = 0) ORDER BY tattoos.created_at DESC 
+0

アクションでパラメータ「q」を使用しているように見えますが、質問はまだわかりませんが、「検索」(奇妙なことにカッコで囲まれています):フォーム。 –

+0

私はちょうど投稿したリンクからこの検索機能をまとめようとしていましたが、text_field_tagにruby APIがあります – rugbert

+0

実際の問題は何ですか?フィールドタグのヘルパーが想定していることをやっているようです。 –

答えて

0

私は私のparamsを取り巻く%を削除し、それがトリックを行うように見えた:

デフsearch_results @tattoos = Tattoo.tagged_with( "#{のparamsを[ :search]} ") end

関連する問題