I have this code
def self.completa(estado_id, cidade_id, bairro_id, segmento_id, pagina, limit = 5)
campos_padrao.estado(estado_id).cidade(cidade_id).bairro(bairro_id).segmento(segmento_id).joins.paginate(:per_page => limit, :page => pagina)
end
named_scope :campos_padrao, lambda { |*args|
{
:select=> (args.first ||
"anuncios.codcli,
anuncios.codseg,
anuncios.nomefanta,
anuncios.irmao,
anuncios.endereco,
anuncios.num,
anuncios.complemento,
anuncios.cep,
anuncios.bairro,
anuncios.cidade,
anuncios.uf,
anuncios.fone,
anuncios.fax,
anuncios.email,
anuncios.site,
anuncios.descricao,
anuncios.fig_anuncio,
anuncios.contrato,
anuncios.uf_anunciar,
anuncios.permalink,
cidades.cidade as cidade_nome,
estados.nome as estado_nome,
segmentos.nome as segmento
") }
}
named_scope :segmento, lambda { |*args|
if (args.first != "todos_segmentos")
{ :conditions => ["anuncios.codseg = ?", args.first] }
else
{ }
end
}
named_scope :estado, lambda { |*args|
{
:conditions => ["anuncios.uf = ?", args.first]
}
}
named_scope :cidade, lambda { |*args|
if (args.first != "todas_cidades")
{ :conditions => ["anuncios.cidade = ?", args.first] }
else
{ }
end
}
named_scope :bairro, lambda { |*args|
if (args.first != "todos_bairros")
{ :conditions => ["anuncios.bairro LIKE ?", "%#{args.first}%"] }
else
{ }
end
}
I get this error.
ctiveRecord::StatementInvalid (Mysql::Error: You have an error
in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '
anuncios.codseg,
anuncios.nomefanta,
' at line 1: SELECT count(anuncios.codcli,
anuncios.codseg,
anuncios.nomefanta,
anuncios.irmao,
anuncios.endereco,
anuncios.num,
anuncios.complemento,
anuncios.cep,
anuncios.bairro,
anuncios.cidade,
anuncios.uf,
anuncios.fone,
anuncios.fax,
anuncios.email,
anuncios.site,
anuncios.descricao,
anuncios.fig_anuncio,
anuncios.contrato,
anuncios.uf_anunciar,
anuncios.permalink,
cidades.cidade as cidade_nome,
estados.nome as estado_nome,
segmentos.nome as segmento
) AS count_anuncios_codcli_anuncios_codseg_anuncios_nomefanta_anuncios_irmao_anuncios_endereco_anuncios_num_anuncios_complemento_anuncios_cep_anuncios_bairro_anuncios_cidade_anuncios_uf_anuncios_fone_anuncios_fax_anuncios_email_anuncios_site_anuncios_descricao FROM `anuncios` INNER JOIN `estados` ON `estados`.uf = `anuncios`.uf INNER JOIN `cidades` ON `cidades`.codcid = `anuncios`.cidade INNER JOIN `segmentos` ON `segmentos`.codseg = `anuncios`.codseg WHERE (anuncios.uf = 'AC') ):
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:223:in
wp_count'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:235:incall'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:235:in
wp_count'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:85:inpaginate'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/collection.rb:87:in
create'
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.8/lib/will_paginate/finder.rb:76:inpaginate'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inwith_scope'