SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Name/Value pairs
-
Mar 2, 2006, 21:21 #1
- 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
-
Mar 6, 2006, 00:06 #2
- 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 -%>
Umm... its late... do you see what I'm saying?
-
Mar 6, 2006, 05:13 #3
- Join Date
- Nov 2005
- Posts
- 85
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use Hash class.
-
Mar 6, 2006, 12:34 #4
- 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
-
Mar 6, 2006, 23:09 #5
- Join Date
- Jun 2004
- Location
- California
- Posts
- 440
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by ricklach
It seems more efficient to use ActiveRecord since they are columns.
Bookmarks