Hi,

I'm new using RoR and I have a ... trouble with
f.collection.select

What I have in a table is ... for example
group code
GroupA 07A
GroupA 08A
GroupA 10B
GroupB 06A
GroupB 11B
GroupB 07B
GroupC 10A
GroupC 09A
GroupC 09B

when I use

<%= f.collection_select :grupo, Equipo.find(:all), :id, :name, prompt:
'Choose a Group' %>

It shows the entire set of groups (9 groups) instead of only 3 (Group
A, Group B, Group C)

How can I make that it shows only one instead of 3 of each one?

--
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@googlegroups.com.
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.

Search Discussions

  • Mathew Vivek at Oct 10, 2011 at 7:41 am
    you r fetching entire Equipo tables.

    you have to use distinct option to get (A,B,C) alone

    regards
    mathew

    --
    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@googlegroups.com.
    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.
  • Walter Lee Davis at Oct 10, 2011 at 12:35 pm

    On Oct 9, 2011, at 11:09 PM, JavierQQ wrote:

    Hi,

    I'm new using RoR and I have a ... trouble with
    f.collection.select

    What I have in a table is ... for example
    group code
    GroupA 07A
    GroupA 08A
    GroupA 10B
    GroupB 06A
    GroupB 11B
    GroupB 07B
    GroupC 10A
    GroupC 09A
    GroupC 09B

    when I use

    <%= f.collection_select :grupo, Equipo.find(:all), :id, :name, prompt:
    'Choose a Group' %>

    It shows the entire set of groups (9 groups) instead of only 3 (Group
    A, Group B, Group C)

    How can I make that it shows only one instead of 3 of each one?
    If you have this specific data in your table, then I'm not sure what your collection_select is meant to represent. Your data are unique at the row level, so if you had a picker with id and name as value and label, which one of the rows in your database should represent GroupA? The one with code 07A? 10B? Those rows would have distinct id values, naturally. By that logic, what you are seeing in your collection_select is precisely what I would expect to see.

    Now if you only want to populate your picker with the "group name" and you want it to be a distinct selection, here's what I use for that:

    <%= f.collection_select( :nationality, (Person.connection.select_values('select distinct(nationality) from people').sort), :to_s, :to_s, {:prompt => true}) %>

    On an admin form, I usually combine that with a bit of JavaScript to create a "combo-box" so the user can add new values to the picker at will. https://gist.github.com/1275185

    Walter
    --
    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@googlegroups.com.
    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.
    --
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 10, '11 at 6:08a
activeOct 10, '11 at 12:35p
posts3
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase