Edit Multiple

Hello,

I’m started from this example
(#198 Edit Multiple Individually - RailsCasts) 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
(Filter on multiple select - Rails - Ruby-Forum).

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 %>

<% for reg in @registrations %> <%= fields_for "registrations[]", reg do |r| %> <% end %> <% end %>
Name Score
<%= reg.student.name %> <%= render "/registrations/form_one", :r => r %>
<%= submit_tag "Submit" %>
<% end %>

registrations/_form_one.html.erb


<%= r.text_field :vote %>

On 7 January 2013 13:22, Lorenz B. [email protected] 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