Re: bad sql after :conditions =>

Phlip
2009-01-11T15:36:45Z

Oskar Szrajer wrote:
> I''ve something like that:
>
> in layout :
> links looks that :
>
> <%= link_to month.strftime(''%B, %Y''),
>
"/?y=#{month.strftime("%Y")}&m=#{month.strftime("%m")}"
%>

Don''t write a raw URI path and query, and don''t use string
surgery to create
one. Add those items as the arguments to url_for():

  <%= link_to month.strftime(''%B, %Y''),
       :y => month.year, :m => month.month %>

(BTW naming a date ''month'' is kind''a tacky...)

That would escape your URI correctly, but this can''t be your problem
because
either way these are just numbers, not punctuation that needs escapes.

> in controler I''ve :
>
>  if params[:y] && params[:m]
>       @posts = Post.find(:all,:order => ''created_at''
,:conditions =>
> [''extract(year from created_at) LIKE ? AND extract(month from
> created_at) LIKE ?'', params[:y], params[:m]] )
>     else
>       @posts = Post.find(:all)
>     end
>
>
> but in console I''ve got that sql code:
>  SELECT * FROM "posts" WHERE (extract(year from created_at) LIKE
E''2009''
> AND extract(month from created_at) LIKE E''01'') ORDER BY
created_at
>
> looks like this E near that LIKE broke everything

I can''t see where the E comes from, but why the LIKE? Your year and
month have
no % in them for LIKE to wildcard.

Can your "functional" test call this action correctly?

--
   Phlip