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 Stabenfeldt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Martin Stabenfeldt 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 StabenfeldtNumber.find(:all, :select=>"DISTINCT some_field, some_field2") -- 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 -~----------~----~----~----~------~----~------~--~---
Martin Stabenfeldt
2007-Mar-14 20:57 UTC
Re: Number.find() shall only return unique values
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 Stabenfeldt
On 14/03/07, Justin Mazzi
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> Martin Stabenfeldt 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 Stabenfeldt
>
>
>
> Number.find(:all, :select=>"DISTINCT some_field, some_field2")
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
Med vennlig hilsen,
Martin Stabenfeldt Mob: 93 44 17 07
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
You can also use .uniq to remove duplicates at the Ruby level. Michael On Mar 14, 1:40 pm, Justin Mazzi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Martin Stabenfeldt 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 Stabenfeldt > > Number.find(:all, :select=>"DISTINCT some_field, some_field2") > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---