SQL and select()

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

@langs = ActiveRecord::Base\.connection\.execute \(@sql\)

then in the view i want to create a select box

&lt;%= select\(&quot;lang&quot;, &quot;lang\_id&quot;, @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