Wildcard and mysql (find_by_sql)

Ja Bo wrote:

Somehow I can not get the wildcard character "%" to work when using a MySQL find_by_sql statement... As soon as I remove the % character everything works... Is there a workaround, another character to be used ?

Thank you very much !

Do you have to drop down to find_by_sql, or can you use a normal find?

Example:

   pages = Page.find(:all, :conditions => "name like 'Wiki%'")

or

   prefix = 'Wiki'    pages = Page.find(:all, :conditions => ['name like ?', prefix + '%'])

The key thing is that you need to put the % in the argument you are supplying, because when Rails does substitution into the placeholder (?) it will be doing escaping and quoting for you.

regards

   Justin