msojka
1
Hi,
I got an address book with a list-column, and I want this dropdown to
display the unique values I have used. So I can sort on e.g. “work” or
“friend”.
<%= select(“post”, “list”, Number.find(:all, :order => “list”,
:conditions => "company = ‘#{$user_company}’ ").collect
{|p| [ p.list ] }, { :include_blank => true }) %>
Is that possible, or do I have to use a low level SQL query?
Best regards,
Martin S.
msojka
2
Martin S. wrote:
Hi,
I got an address book with a list-column, and I want this dropdown to
display the unique values I have used. So I can sort on e.g. “work” or
“friend”.
<%= select(“post”, “list”, Number.find(:all, :order => “list”,
:conditions => "company = ‘#{$user_company}’ ").collect
{|p| [ p.list ] }, { :include_blank => true }) %>
Is that possible, or do I have to use a low level SQL query?
Best regards,
Martin S.
Number.find(:all, :select=>“DISTINCT some_field, some_field2”)
msojka
3
You can also use .uniq to remove duplicates at the Ruby level.
Michael
On Mar 14, 1:40 pm, Justin M. [email protected]
msojka
4
Thanks,
With some minor syntax editing, it workes like a sharm! 
Thanks!
<%= select(“post”, “list”, Number.find(:all, :select => ‘DISTINCT
list’, :conditions => "company = ‘#{$user_company}’ ").collect
{|p| [ p.list ] }, { :include_blank => true }) %>
Rgds,
Martin S.
On 14/03/07, Justin M. [email protected] wrote:
{|p| [ p.list ] }, { :include_blank => true }) %>
–
Posted via http://www.ruby-forum.com/.
–
Med vennlig hilsen,
Martin S. Mob: 93 44 17 07