Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## my controller
- class AttendanceController < ApplicationController
- def index
- meeting_id = params[:id]
- unless meeting_id
- flash[:message] = "you can take attendance without specifying a meeting"
- redirect_to admin_index
- end
- @my_meeting = Meeting.find(meeting_id)
- @time_slot = @my_meeting.time_slot
- @boot_camp = @time_slot.boot_camp
- @potential_users = User.find :all, :select => 'distinct users.*',
- :joins => {:orders => {:registrations => :time_slot}},
- :conditions => ['time_slots.id = ?',@my_meeting.time_slot.id]
- # ^^^^^^^^ why does that work?
- @meeting_users = MeetingUser.find(:all,
- :conditions => ['meeting_id = ?',@my_meeting.id])
- end
- def take_attendance
- params[:user_ids] ||= []
- users = params[:user_ids]
- unless (users.empty? || params[:meeting_id].empty? || !request.post?)
- meeting_id = params[:meeting_id].to_i
- @existing_attendees = \
- Meeting.find(meeting_id).meeting_users.map{|mu| mu.user}
- users.each do |user|
- if @existing_attendees.detect{|ea| ea.id = user.id} ||
- # they already are attending and we say they are
- elsif # the user was checked, but now is not
- else # the user was never checked, create
- mu = MeetingUser.create(:user_id => user.id,
- :meeting_id => meeting_id)
- end
- end
- end
- end
- end
- ## my view
- <div class="floatLeft width25">
- <!-- Left thumbnail column -->
- <!-- Left thumbnails end -->
- </div>
- <!-- Left thumbnails end -->
- <!-- Right column -->
- <div class="floatRight width75">
- <h1><%= attendance_event(@boot_camp,@my_meeting,@time_slot) %></h1>
- <% if @potential_users.empty? %>
- <p>There are no potential users for
- the time slot from <%= @time_slot.start_to_finish %></p>
- <% else %>
- <% form_for :attendees,
- :url => {:action => 'take_attendance'} do |f| %>
- <%= hidden_field_tag 'meeting_id', @my_meeting.id %>
- <% @potential_users.each do |usr| %>
- <%= check_box_tag "user_ids[]",
- usr.id,
- @meeting_users.include?(usr) %>
- <%= usr.full_name %><br />
- <% end %>
- <p>
- <%= f.submit "Update" %>
- </p>
- <% end %>
- <% end %>
- <%= link_to "Return to meetings for #{@boot_camp.title}",
- boot_camp_time_slot_url(@boot_camp.id,@my_meeting.time_slot) %>
- </div>
Add Comment
Please, Sign In to add comment