Hi! I need the results of a custom SQL query to create a list in a view. Thats the query: @classes = ActiveRecord::Base.connection.execute "SELECT DISTINCT CLASS FROM SymbolsMatch_MASTER" And thats the part of the view: <ul> <% for class_name in @classes do %> <li> <a href="#"><%= class_name %></a> </li> <% end %> but @classes is always NULL here... What am I doing wrong? Thx lack -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6 Nov 2008, at 10:55, Günther Lackner wrote:> > Hi! > > I need the results of a custom SQL query to create a list in a view. > > Thats the query: > > @classes = ActiveRecord::Base.connection.execute "SELECT DISTINCT > CLASS > FROM SymbolsMatch_MASTER" >execute just executes without returning anything. If you want the result then you want one of select_all/select_values/select_value etc... (in this particular case select_values would do the trick) Fred> And thats the part of the view: > > <ul> > <% for class_name in @classes do %> > <li> > <a href="#"><%= class_name %></a> > </li> > <% end %> > > but @classes is always NULL here... > > What am I doing wrong? > > Thx > lack > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> @classes = ActiveRecord::Base.connection.execute "SELECT DISTINCT CLASS > FROM SymbolsMatch_MASTER"This is the trick: ActiveRecord::Base.connection.execute(your_sql).extend(Enumerable).to_a -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---