SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot ricklach's Avatar
    Join Date
    Nov 2004
    Location
    Victoria BC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Name/Value pairs

    I have a table with id, name, value that is used to configure my application. I want to produce a form that has a number of fields that a new user would fill in to set-up the program - this is the source of the name/value pairs. Is there a way with ror to take all of the name value pairs from a form and add them to the database in an iterative fashion. For example: name/bob save, phone/123-456-1234 save, etc.

    Rick

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use a hidden tag to store the count of the fields present and iterate over each if the user is entering the name/value pairs himself. If the name value is already in there and the user is merely filling in multiple "values" for "names" which already exists, you could do:

    Code:
    <%= NameValue.find(:all).each do |pair| -%>
    <%= pair.name %>: <%= text_field_tag 'value_' pair.id.to_s, pair.value %><br />
    <% end -%>
    Then iterate over each and check to see if its filled in on the controller side.
    Umm... its late... do you see what I'm saying?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use Hash class.

  4. #4
    SitePoint Zealot ricklach's Avatar
    Join Date
    Nov 2004
    Location
    Victoria BC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you provide an example of using hash class to perform the task?

    Rick

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ricklach
    Can you provide an example of using hash class to perform the task?

    Rick
    Ditto. I'd like to see how you would use the hash class for these DB values...
    It seems more efficient to use ActiveRecord since they are columns.
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer


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
  •