gpt4 book ai didi

ruby-on-rails - Rails 4 考勤系统

转载 作者:数据小太阳 更新时间:2023-10-29 08:03:38 24 4
gpt4 key购买 nike

您好,我实际上正在努力构建一个在 Rails 4 上实现出勤模型的 Rails 4 应用程序,我在 stackoverflow 上发现了两个问题,但它们是在 2012 年发布的,当我尝试关注它们时它失败了。

这是我得到的最接近的on stackoverflow

编辑:我已经有了教室 View 并列出了学生。并且可以将学生分配到教室,但问题是让学生进入新的attsheet并将他们保存到attendance

这是我现在拥有的

# Attendance
# take student as a single entry for :attsheet and
# has a :attended (boolean) and remarks as well
class Attendance < ActiveRecord::Base
belongs_to :student
belongs_to :attsheet
end

#Attsheet which means attendance sheet
#has :post_date and :remark
class Attsheet < ActiveRecord::Base
belongs_to :classroom
has_many :attendances
accepts_nested_attributes_for :attendances
end

class Student < ActiveRecord::Base
belongs_to :school
has_and_belongs_to_many :classrooms
has_many :attendances
end

class Classroom < ActiveRecord::Base
belongs_to :school
has_and_belongs_to_many :students
has_many :attsheets

validates :class_name, presence: true
end

我希望教室能够为每个学生创建新的出勤记录或查看出勤文件。

我现在可以在类里面完成此操作,但我不知道接下来要为 Controller 和 View 做什么

 $ = link_to "New Attendance", new_school_classroom_attsheet_path(@school, @classroom, @attsheet) 

最佳答案

在 attandances_controller 中,

class AttendancesController < ApplicationController

before_filter :set_parents

def new
@attendance= @classroom.attendances.new
end

def create
@attendance= @classroom.attendances.new(params[:milestone])

if @attendance.save
redirect_to ....
else
render :action=>:new
end
end

def set_parents
@school= School.find(params[:school_id])
@classroom= @school.classrooms.find(params[:classroom_id])
end
end

并在 attendacen 的 _form.html.erb 中,

<%= form_for(@school, @classroom, @attendance]) do |f|%>
<% if @attendance.errors.present? %>
<ul class="warning">
<% @attendance.errors.full_messages.each do |message| %>
<li><%= message%></li>
<% end %>
</ul>
<% end %>

<h2>Attendance</h2>
.........
<%= f.submit button %>
<% end %>

这将提交 fotm 以创建出勤 Action

关于ruby-on-rails - Rails 4 考勤系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30662221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com