I don’t know where I make the mistake
if i have an sql in the controller like this:
@sql = "select result.lang_id as id,pv_langs.name as name from
((SELECT pv_lang_id as lang_id FROM pv_castings)
UNION (SELECT sv_lang_id as lang_id FROM pv_castings)) as result
join pv_langs on result.lang_id = pv_langs.id GROUP BY
result.lang_id"
@langs = ActiveRecord::Base.connection.execute (@sql)
then in the view i want to create a select box
<%= select("lang", "lang_id", @langs.map {|p| [ p.name, p.id ] })
%>
can you explain why it dont work?
Sergio
On Jan 8, 4:17Â pm, Quijote70 [email protected] wrote:
  @langs = ActiveRecord::Base.connection.execute (@sql)
then in the view i want to create a select box
  <%= select(“lang”, “lang_id”, @langs.map {|p| [ p.name, p.id ] })
%>
can you explain why it dont work?
execute returns a database specific result set object (eg
Mysql::Result for mysql etc.). You probably want something like
select_all that returns an array of hashes
Fred
then in the view i want to create a select box
<%= select("lang", "lang_id", @langs.map {|p| [ p.name, p.id ] })
%>
Try this :-
<%= select(“lang”, “lang_id”, @langs.map {|p| [ p[‘name’], p[‘id’] ] })
%>
or
<%= select(“lang”, “lang_id”, @langs.map {|p| [ p[1], p[0] ] }) %>
Perfect, yes I was concentred to the map and I didnt look the execute
On Fri, 8 Jan 2010 08:57:09 -0800 (PST), Frederick C.