SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    holding selection in select_tag

    I'm new to rails and I haven't seen much decent documentation on using the select_tag helper.

    I'm having 2 problems:

    Holding the selected item in the select box after the form is submitted and also keeping the order of the select items consistent.

    Here's the code I'm trying:

    Code:
    <%=select_tag('public_all_categories', options_for_select({ :Public => 1, '--Choose--' => '',  :Private => 0})) %>
    Thanks for your help

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you need is something to put selected="selected" on one of those <options>, right? select_tag doesn't have a part in that, it is getting its data from options_for_select.

    http://api.rubyonrails.org/classes/A...r.html#M000510
    Couple examples on how to do the selected thing in there.

    Hashes don't have an order, so they don't have a consistent order. You need to hand it an Array. Hash has a sort method that outputs an Array, may be what you need.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help. I solved the problem w/ this little bit:

    <%= select_tag('public_all_categories',
    options_for_select({ :Public => 1, '--Choose--' => '', :Private => 0},
    params[ublic_all_categories])) %>

    Problem solved!!!


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
  •