Ruby on Rails Sunday, October 31, 2010

Thanks Michael
I have tried that along with other versions of '%search_item%'without
any joy. Just tried it again. it does not throws an error, but it
returns nothing.
self.where('section = ?', search_item) works with the full word
'Gardening', but not 'Gar'
self.where('section = ?', '%search_item%') does not work and you
cannot use %without a ' or "
self.where('section = ?', '%'search_item'%') is an internal
server error
self.where('section = ?', '%'+search_item+'%') no go either.
Don

On Oct 31, 1:42 pm, Michael Pavling <pavl...@gmail.com> wrote:
> On 31 October 2010 12:09, MDM <don.m...@gmail.com> wrote:
>
> > Thanks for that, but I am still getting a syntax error. Now:-
> > SQLite3::SQLException: near "%": syntax error: SELECT
> > "homepages".* FROM       "homepages"  WHERE     (section = %'Gar'%)
>
> You can't put the question mark inside the percentage signs, as Rails
> SQL-escapes the variable and wraps it in appropriate delimiters...
> hence your error. You need to wrap your string in percentages one way
> or another and pass that in:
>
> self.where('section = ?', "%#{search_item}%")

--
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