SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SOLVED - dynamic select values

    Hello, I have a view with a select
    Code:
    <%= form.select :rank, ... %>
    and I would like the showed options were 1 to 10 without the already taken values. For instance if it is already present a priority with rank = 4 the showed options must be 1,2,3,5,6,7,8,9,10

    Is there a simple rails way to do that ???

    Thanks
    Last edited by macsig; Feb 6, 2008 at 16:21. Reason: SOLVED
    Alla prossima ...

  2. #2
    SitePoint Member vSkyfluxx's Avatar
    Join Date
    Mar 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the controller action, just take the values it already has out of the collection that will be passed to form.select
    "Earth smiles in flowers" - Ralph Waldo Emerson
    DuskDesigns

  3. #3
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your answer but I don't understand
    Could you please make an example.

    Have a nice day!
    Alla prossima ...

  4. #4
    SitePoint Member vSkyfluxx's Avatar
    Join Date
    Mar 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, say this list of select options is relevant when editing an article. So you'd have an edit action in your controller:

    ### /app/controllers/articles_controller.rb
    Code Ruby:
    class ArticlesController < ApplicationController
       ...
       def edit
          @article = Article.find(params[:id])
          @rankings = Rankings # this could be a constant or fetched from the database
          @rankings.delete(@article.ranking)
       end
       ...
    end

    And use @rankings likewise in your view:

    ### /app/views/articles/edit.html.erb
    Code Ruby:
    <h1>Editing an Article</h1>
    ...
       <%= form.select 'article', 'rank', @rankings %>
    ...

    For more information check out:
    http://api.rubyonrails.org/classes/A...onsHelper.html
    http://wiki.rubyonrails.org/rails/pa...mOptionHelpers
    "Earth smiles in flowers" - Ralph Waldo Emerson
    DuskDesigns

  5. #5
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks buddy
    with a couple of small changes it works as I need


    have a good 1!
    Alla prossima ...


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
  •