首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails 4考勤系统

Rails 4考勤系统
EN

Stack Overflow用户
提问于 2015-06-05 08:50:28
回答 2查看 1.8K关注 0票数 3

嗨,我真的很难在Rails 4上构建一个rails 4应用程序,我在rails 4上发现了两个关于堆栈溢出的问题,但是它们是在2012年发布的,但是当我尝试跟踪它们时,它失败了。

这是我买到的最接近on stackoverflow

编辑:我已经对教室有了一个看法,并列出了学生。可以分配学生进入教室,但问题是让学生进入一个新的记事本,并将他们保存到考勤中。

下面是我现在的情况

代码语言:javascript
复制
# 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

我希望教室能够为每个学生创建一个新的出勤率或查看出勤率档案。

我现在可以在教室里做这件事了,但是我不得不为控制器和视图下一步做些什么。

代码语言:javascript
复制
 $ = link_to "New Attendance", new_school_classroom_attsheet_path(@school, @classroom, @attsheet) 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-10 04:11:51

我通过做

我把攻击记录改成了attendance_list

代码语言:javascript
复制
def new
    @attendance_list = @classroom.attendance_lists.new

    @attendance_list.attendances = @classroom.student_ids.map do |student_id|
      @attendance_list.attendances.build(student_id: student_id)
    end
end

def create
    @attendance_list = @classroom.attendance_lists.new(attendance_list_params)
    @attendance_list.classroom_id = params[:classroom_id]

    respond_to do |format|
      if @attendance_list.save
        format.html {redirect_to school_classroom_path(@school, @classroom), notice: "You added the attendance!" }
      else

      redirect_to new_school_attendance_list_path(attendance_list_params)
      end
   end
end

用简单的字段

代码语言:javascript
复制
= f.simple_fields_for :attendances do |g|
  = g.input :student_id, as: :hidden
  ...... more fields ...
票数 1
EN

Stack Overflow用户

发布于 2015-06-05 09:02:30

在attandances_controller中,

代码语言:javascript
复制
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

在_form.html.erb中,

代码语言:javascript
复制
<%= 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以创建出勤操作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30662221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档