Hello, I'm started from this example (http://railscasts.com/episodes/198-edit-multiple-i...) to create a view to update multiple fields. My goal is permit at the user to update all exam scores in the same view. I know the students registered at the exam, so I did't need a multiple selection. I have showed my DB structure in this post (http://www.ruby-forum.com/topic/4409047#new). I see the view in the right way, but the score don't update. Below, my code, thanks for the help. # registrations_controller.rb -------------------------------------------- def update_multi @registrations = Registration.update(params[:ids].keys, params[:registrations].values).reject { |p| p.errors.empty? } if @registrations.empty? format.html { redirect_to @registration.exam, notice: 'Exam Updated.' } else redirect_to @registration.exam end end # routes.rb ------------------------------------------------------------- resources :registrations do collection do put 'update_multi' end end resources :exams do member do get 'score' end end # exam_controller.rb ----------------------------------------------------- def score @exam = Exam.find(params[:id]) @registrations = Registration.where("exam_id = ?", params[:id]) end # exams/score.html.erb --------------------------------------------------- # ..code to show data exam... <%= form_tag 'registrations/update_multi', :method => :put do %> <table> <tr> <th>Name</th> <th>Score</th> </tr> <% for reg in @registrations %> <tr> <td> <%= reg.student.name %> </td> <%= fields_for "registrations[]", reg do |r| %> <td> <%= render "/registrations/form_one", :r => r %> </td> <% end %> </tr> <% end %> </table> <div class="actions"> <%= submit_tag "Submit" %> </div> <% end %> # registrations/_form_one.html.erb --------------------------------------- <%= r.text_field :vote %>
on 2013-01-07 14:22
on 2013-01-07 14:31
On 7 January 2013 13:22, Lorenz Blackbird <lists@ruby-forum.com> wrote: > > I see the view in the right way, but the score don't update. Below, my > code, thanks for the help. Have a look at the Rails Guide on debugging, which will show you techniques that you can use to debug the code. Once you have worked out which bit of code is not working then, if you still cannot see the problem, come back with details of exactly what the problem is. Hint: first look in development.log to check that the parameters are being passed correctly. Colin
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.