Ruby on Rails Monday, August 1, 2011

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@googlegroups.com.
> 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@googlegroups.com.
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.

No comments:

Post a Comment