私は Leave_type モデルを持っています。このモデルを使用して、年次休暇 20 日、病気休暇 5 日などを割り当てました。
別のモデルは leave_apply です。次のような属性があります。
:teacher_id,:leave_type_id,:leave_balance,:from_date,:to_date,:day_count, :comment たとえば、教師が年次休暇を 5 日間取得した場合、休暇残日数は 5 (すなわち 10-5)。leave_type と teacher に基づいています。次のコードがありますが、機能しません。
コントローラ
if params[:balance].present? and params[:teacher].present?
@counts = LeaveType.find(params[:balance]).leave_count
@leave = LeaveApply.find_by_teacher_id_and_leave_type_id(params[:teacher],
params[:balance])
@count = @counts - @leave.day_count
respond_to do |format|
format.js
end
end
モデル
class LeaveApply < ActiveRecord::Base
attr_accessible :teacher_id,:leave_type_id,:leave_balance,:from_date,:to_date,:day_count,
:comment
#associations
belongs_to :leave_type
belongs_to :teacher
end
私を助けてください..