我正在尝试创建一个表格,允许您每天输入或更新出勤时间,并能够显示每个孩子每周的记录。我在试图弄清楚如何用这样的表格实现表格时遇到了麻烦:
<- Previous Week Next Week ->
| Child | Monday 5/6 | Tuesday 5/7 | Wednesday 5/8 | Thursday 5/9 | Friday 5/10 |
| child1 | __________ | ___________ | _____________ | ____________ | ___________ |
| child2 | __________ | ___________ | _____________ | ____________ | ___________ |
Submit
我目前有两个具有 has_one 和 has_many 关系的模型:
class Child < ActiveRecord::Base
validates :first, presence: true
validates :last, presence: true
attr_accessible :age, :first, :last, :created_at
belongs_to :site
has_many :attendances
end
class Attendance < ActiveRecord::Base
attr_accessible :date, :time, :child_id
belongs_to :child
scope :thisweek, lambda {
where("date between ? and ?", Date.today.at_beginning_of_week, Date.today.at_end_of_week)
}
end
我还有 2 个用于儿童和出勤的脚手架控制器,我能够通过如下查询加载一周所需的所有数据:
class AttendancesController < ApplicationController
def index
@site = Site.find(params[:site_id]) #using nested resources /site/1/attendances
@children = @site.children.all
@attendances = Attendance.thisweek.find_all_by_child_id(@children)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @attendances }
end
end
end
除此之外,我还停留在如何将这些数据转换为上述形式的问题上。