SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    multiple select box Helpers

    Hi everyone.

    Is there an easy helper function to create a multiple select box ie
    "<select .... multiple="multiple">...</select>.

    Ive looked a the select function but can't see how to do this using it.

    What im trying to do is assign a "document" to multiple different clients.

    ie client -> has_and_belongs_to :documents and vise versa

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    From http://wiki.rubyonrails.com/rails/pa...mOptionHelpers, but adapted to your situation
    Code:
    <% @selected = @document.clients.collect { |d| d.client_id.to_i } %>
    <select name="document[client_ids][]" size="5" multiple="multiple">
      <%= options_from_collection_for_select(@clients, "id", "full_name", @selected) %>
    </select>

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks vgarcia that will be a great help.

  4. #4
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm actually working on extracting some code from a current project that lets you use two multiple select boxes to assign one object to another object in a many to many relationship, using AJAX. It might also join many to many relationships that use a join model through relationships) - I should hopefully be able to release this as a Rails plugin so stay tuned.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •