Hi! I want to make a search box. I tried search box by using tag_name but it didn''t work. # posts_controller.rb @tag = Tag.find_all_by_tag_name(params[:search_string]) is work fine.But It only return all matched words. I tried below their code to be able to fuzzy search. But they didn''t work. @tag = Tag.find_all_by_tag_name(''%'' +params[:search_string]+''%'') @tag = Tag.find(:all,:conditions => [''tag_name LIKE ?'',"%{:search_string}%"]) Please help me some advise! thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 1, 2011, at 10:59 AM, 原田伸也 wrote:> > Hi! I want to make a search box. I tried search box by using > tag_name but it didn''t work. > > > # posts_controller.rb > > @tag = Tag.find_all_by_tag_name(params[:search_string]) > > is work fine.But It only return all matched words. > > I tried below their code to be able to fuzzy search. > > But they didn''t work. > > > @tag = Tag.find_all_by_tag_name(''%'' +params[:search_string]+''%'') > > @tag = Tag.find(:all,:conditions => [''tag_name LIKE ?'',"% > {:search_string}%"])Try this: @tag = Tag.find(:all,conditions => [''tag_name LIKE "%? %"'',params[:search_string]] Walter> > > Please help me some advise! thanks. > > > > > > > > > > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > .-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 August 2011 15:59, 原田伸也 <haradashinya@gmail.com> wrote:> > Hi! I want to make a search box. I tried search box by using tag_name but > it didn''t work. > > > # posts_controller.rb > > @tag = Tag.find_all_by_tag_name(params[:search_string]) > > is work fine.But It only return all matched words. > > I tried below their code to be able to fuzzy search. > > But they didn''t work. > > > @tag = Tag.find_all_by_tag_name(''%'' +params[:search_string]+''%'') > > @tag = Tag.find(:all,:conditions => [''tag_name LIKE > ?'',"%{:search_string}%"])You forgot the # and the params[]. Should be possibly @tag = Tag.find(:all,:conditions => [''tag_name LIKE ?'',"%#{params[:search_string]}%"]) If still not working look in the log and you will see the sql generated which should give you a clue as to the problem. Colin> > > Please help me some advise! thanks. > > > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
To Colin Thanks! It worked fine! I struggled for this problem for a long time. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 August 2011 17:10, 原田伸也 <haradashinya@gmail.com> wrote:> To Colin > > Thanks! It worked fine! > I struggled for this problem for a long time.OK, Walter''s suggestion should have worked also. If you had looked in the log you would have seen the sql and been able to work it out yourself probably. Have you had a look there to see what it shows so that next time you have a problem you can look there? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I see. :) Tag Load (0.4ms) SELECT "tags".* FROM "tags" WHERE (tag_name LIKE ''%thanks%'') Rendered posts/find.html.erb within layouts/application (1.9ms) Completed 200 OK in 15ms (Views: 6.3ms | ActiveRecord: 0.4ms) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.