Hi,
I am fairly new to RoR and hacking on a small application. In order to display existing values of some model column in a form, I currently do:
<% form_for([@testbox, @testitem]) do |f| %>
<%= f.label :sortkey %><br />
<%= f.collection_select :sortkey, Testitem.groups , :sortkey, :sortkey, {:include_blank => true} %>
<% end %>
In the model Testitem
I have:
def Testitem.groups
return find_by_sql("SELECT DISTINCT sortkey from testitems; ")
end
I am sure there is a more elegant solution to this? I have tried find(:all).sortkey.unique
but that throws undefined method 'sortkey' for #<Array:0x59d1b60>