On 7 January 2013 13:22, Lorenz Blackbird
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Hello,
>
> I''m started from this example
> (http://railscasts.com/episodes/198-edit-multiple-individually) 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.
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
>
>
> # 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 %>
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.