Forum: Ruby on Rails Custom SQL queries

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4b1b2afb2d72022424eb2edc6db4d375?d=identicon&s=25 Günther Lackner (lackyg)
on 2008-11-06 11:55

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:

 <% for class_name in @classes do %>
   <a href="#"><%= class_name %></a>
<% end %>

but @classes is always NULL here...

What am I doing wrong?

81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-06 12:11
(Received via mailing list)
On 6 Nov 2008, at 10:55, Günther Lackner wrote:

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)

059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2008-11-06 12:15
> @classes = ActiveRecord::Base.connection.execute "SELECT DISTINCT CLASS
> FROM SymbolsMatch_MASTER"

This is the trick:
This topic is locked and can not be replied to.