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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 8, 4:17 pm, Quijote70 <sergio.angele...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> Sergio-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > 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] ] }) %> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 8, 4:17 pm, Quijote70 <sergio.angele...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 >> Sergio--001485e9a570a64a3c047ce2e6d1 Content-Type: text/plain; charset=ISO-8859-1 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --001485e9a570a64a3c047ce2e6d1--