This works fine, until I type an entry into my search box that has a
single quote, such as “John’s Company.” ActiveRecord spits back an error
at me along the lines of “Mysql::Error: #42000You have an error in your
SQL syntax;.” I know single quotes need to be escaped in MySQL, but I
assumed rails took care of this automatically, just like it does when I
create or update projects. Is there an easy way to do this, or will I
need to run a gsub on my params[:query] variable?
in the next parameter being escaped and inserted where the ? is.
I’ve never been able to get this kind of query to work in a
parametrized :conditions argument. Every time I try to do this, the
results would be
“name like ‘%‘John’%’”
As you can see, it puts extra single quotes around the parameter,
making this an invalid SQL statement.
Too bad sanitize_sql isn’t available to us without hacking into the
source.
–
Sean W.
master nerd of
i heart squares, Co.
3711 N. Ravenswood Ave. #147 Chicago, IL 60613
Ph. (773) 531-6301 Fx. (773) 529-7041 http://www.iheartsquares.com