Guest User

Untitled

a guest
Apr 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. ## my controller
  2.  
  3. class AttendanceController < ApplicationController
  4.  
  5. def index
  6. meeting_id = params[:id]
  7. unless meeting_id
  8. flash[:message] = "you can take attendance without specifying a meeting"
  9. redirect_to admin_index
  10. end
  11. @my_meeting = Meeting.find(meeting_id)
  12. @time_slot = @my_meeting.time_slot
  13. @boot_camp = @time_slot.boot_camp
  14. @potential_users = User.find :all, :select => 'distinct users.*',
  15. :joins => {:orders => {:registrations => :time_slot}},
  16. :conditions => ['time_slots.id = ?',@my_meeting.time_slot.id]
  17. # ^^^^^^^^ why does that work?
  18. @meeting_users = MeetingUser.find(:all,
  19. :conditions => ['meeting_id = ?',@my_meeting.id])
  20. end
  21.  
  22. def take_attendance
  23. params[:user_ids] ||= []
  24. users = params[:user_ids]
  25. unless (users.empty? || params[:meeting_id].empty? || !request.post?)
  26. meeting_id = params[:meeting_id].to_i
  27. @existing_attendees = \
  28. Meeting.find(meeting_id).meeting_users.map{|mu| mu.user}
  29. users.each do |user|
  30. if @existing_attendees.detect{|ea| ea.id = user.id} ||
  31. # they already are attending and we say they are
  32. elsif # the user was checked, but now is not
  33.  
  34. else # the user was never checked, create
  35. mu = MeetingUser.create(:user_id => user.id,
  36. :meeting_id => meeting_id)
  37.  
  38. end
  39. end
  40. end
  41.  
  42. end
  43. end
  44.  
  45. ## my view
  46.  
  47. <div class="floatLeft width25">
  48. <!-- Left thumbnail column -->
  49.  
  50. <!-- Left thumbnails end -->
  51. </div>
  52. <!-- Left thumbnails end -->
  53. <!-- Right column -->
  54. <div class="floatRight width75">
  55. <h1><%= attendance_event(@boot_camp,@my_meeting,@time_slot) %></h1>
  56. <% if @potential_users.empty? %>
  57. <p>There are no potential users for
  58. the time slot from <%= @time_slot.start_to_finish %></p>
  59. <% else %>
  60. <% form_for :attendees,
  61. :url => {:action => 'take_attendance'} do |f| %>
  62. <%= hidden_field_tag 'meeting_id', @my_meeting.id %>
  63. <% @potential_users.each do |usr| %>
  64. <%= check_box_tag "user_ids[]",
  65. usr.id,
  66. @meeting_users.include?(usr) %>
  67. <%= usr.full_name %><br />
  68. <% end %>
  69. <p>
  70. <%= f.submit "Update" %>
  71. </p>
  72. <% end %>
  73. <% end %>
  74.  
  75. <%= link_to "Return to meetings for #{@boot_camp.title}",
  76. boot_camp_time_slot_url(@boot_camp.id,@my_meeting.time_slot) %>
  77. </div>
Add Comment
Please, Sign In to add comment