personal-selected_course/app/models/student_assignment.rb

23 lines
888 B
Ruby

class StudentAssignment
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :assignment_content, as: :slug_title, type: String, default: ""
has_many :student_assignment_files, :dependent => :destroy, :autosave => true
accepts_nested_attributes_for :student_assignment_files, :allow_destroy => true
belongs_to :course_assignment
belongs_to :member_profile
def display_created_at
self.created_at.strftime("%Y-%m-%d %H:%M")
end
def display_updated_at
self.updated_at.strftime("%Y-%m-%d %H:%M")
end
def display_student_assignment_files
self.student_assignment_files.map{ |f|
next if f.file.file.nil?
title = (f.title.blank? ? f.file.file.original_filename : f.title)
"<a href=\"#{f.file.url}\" title=\"#{title}\">#{title}</a>"
}.join("<br>").html_safe
end
end