Using Ruby on Rails 4, I'm trying to loop through my student list, and insert their ID's into the attendances table via a checkbox.
I'm getting the following error:
No route matches {:action=>"mark_attendance", :controller=>"attendance"} missing required keys: [:student_id, :attendance_id]
My files:
routes.rb
resources :static
resources :student do
resources :attendance
end
devise_for :users
root :to => "static#index"
student_controller.rb
class StudentController < ApplicationController
def index
@students = Student.all
end
def show
@student = Student.find(params[:id])
end
def create
@student = Student.new(student_params)
respond_to do |format|
if @student.save
format.html { redirect_to @student, notice: 'Student was successfully added.' }
format.js
format.json { render action: 'show', status: :created, location: @student }
else
format.html { render action: 'new' }
format.json { render json: @student.errors, status: :unprocessable_entity }
end
end
end
def student_params
params.require(:event).permit(:name, :contact, :balance)
end
end
student.rb
class Student < ActiveRecord::Base
has_and_belongs_to_many :attendances
attr_accessible :name, :contact, :balance
end
attendance_controller.rb
class AttendanceController < ApplicationController
def create
@student = Student.new(attendee_params)
respond_to do |format|
if @student.save
format.html { redirect_to @student, notice: 'Students were added successfully.' }
format.js
format.json { render action: 'show', status: :created, location: @student }
else
format.html { render action: 'new' }
format.json { render json: @student.errors, status: :unprocessable_entity }
end
end
end
def mark_attendance
end
def attendee_params
params.require(:event).permit(:student_id, :date)
end
end
attendance.rb
class Attendance < ActiveRecord::Base
belongs_to :student
attr_accessible :student_id, :date
end
index.html.erb
<div class="row">
<div class="content marketing">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<tr>
<th> </th>
<th>ID</th>
<th>Name</th>
<th>Contact</th>
<th>Balance</th>
<th style="width: 8%"> </th>
</tr>
<% form_tag student_attendance_mark_attendance_path do %>
<% @students.each do |s| %>
<tr>
<td><%= check_box_tag "student_ids[]", s.id %></td>
<td><%= s.id %></td>
<td><%= s.name %></td>
<td><%= s.contact %></td>
<td><%= number_to_currency(s.balance) %></td>
<td><%= link_to "View", student_path(s.id), :class => "btn btn-primary" %></td>
</tr>
<% end %>
<% end %>
</table>
</div><!-- End Table Responsive -->
</div><!-- End col-md-8 -->
<div class="col-md-3"></div>
</div>
</div><!-- End Row -->
I would love to know what the error is or how I would be able to do this using checkboxes.