ruby - Generate attendance view/form in rails for all students -


i new rails , struggling on sounds easy can not work. have 2 models students , attendances.

student model:

name lastname classroom_id 

attendance model:

present:boolean absent:boolean halfday:boolean attnd_date:date student_id 

students has_many :attendances , attendance belongs_to :student.

i can make entry individual student , take attendance want generate view show students (or show students given classroom) , next each student name show 3 checkboxes can mark present , absent in 1 go rather 1 one , submit form.

any here appreciated. using rails 4 , ruby 2.2.0

thanks

you can make edit action, find classroom want mark attendances.

class attendancescontroller < applicationcontroller   def edit     @classroom = classroom.find(<classroom-id>)   end    def update   end end 

in view edit.html.erb

<%= form_for(@classroom, url: '/attendances/:id', method: :put) |f| %>   <table>     <%- @classroom.students.each |student| %>       <tr>         <td><%= student.name %></td>         <td><%= checkbox_tag "attendances[#{student.id}][present]" %></td>         <td><%= checkbox_tag "attendances[#{student.id}][absent]" %></td>         <td><%= checkbox_tag "attendances[#{student.id}][halfday]" %></td>       </tr>     <% end %>   </table>    <%= f.submit %> <% end %> 

this way, when submit form, receive these params in update action:

`{ attendances: { '1' => { present: false, absent: true, halfday: false }, '2' => { present: true, absent: false, halfday: false }, ... } }`. 

then can write logic in action save these details database.

note: kind of pseudo code. please check syntax , options different html tags.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -