Hi All,
Noob question -- but perhaps a combo of Ruby and Rails noobness.
I have a table of "scores" and there are 150 "most recent"
scores per
user.
I can retrieve those scores and display them in a form for the
user. The user can update any and all scores. I''m now trying
to implement the database "update" functionality (this is my first
attempt
at form processing). I''ve read through a few examples of using
multiple models in forms and learned that I need to uniquely identify
each
field, which I''m able to do (I think).
----------------
<% form_for :score, :url => ''/users/update_scores'' do
|form| %>
<% for score in @scores %>
<% fields_for "scores[#{score.element.id}]", score do |f| %>
<tr><td><%= f.text_field :rating, :size => 2
%></td>
<td><%= score.element.description
%></td></tr>
<% end %>
<% end %>
<% end %>
This gives me HTML that looks like:
<tr><td><input id="scores[1]_rating"
name="scores[1][rating]" size="2"
type="text" value="5" /></td><td>Question for
this score</td></tr>
<tr><td><input id="scores[2]_rating"
name="scores[2][rating]" size="2"
type="text" value="1" /></td><td>Question for
this score</td></tr>
<tr><td><input id="scores[3]_rating"
name="scores[3][rating]" size="2"
type="text" value="1" /></td><td>Question for
this score</td></tr>
.... all the way up to name="scores[150][rating]"
------------------
I''m confused about how to reference each text field back in my
controller.
I''ve tried params[:scores] and params[:scores][rating] along with
many other attempts that I can''t remember now. I''ve been
getting
"nil" errors, or various syntax errors. Perhaps I''m using
fields_for
incorrectly?
My overall goal is to compare each field in the submitted form to
it''s original value (by requerying the database?) and only record new
score records for fields that have changed (I need to keep the old
records in the table so I can compare how the scores are changing over
time). If the
user only changes the rating for the 2nd question, I record a new record
only for that change and timestamp it.
Thanks in advance for your time.
Rog
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---