forked from bofh/fetsite
AutoCommit Fre Jul 31 21:03:04 CEST 2015
This commit is contained in:
@@ -10,8 +10,8 @@ class Ability
|
||||
end
|
||||
end
|
||||
user ||= User.new # guest user (not logged in)
|
||||
|
||||
|
||||
can :manage, Survey::Question
|
||||
can :manage, Comment
|
||||
#-----------------------------------------------------
|
||||
# Rechteverwaltung fuer Studien Modul
|
||||
can [:show, :index], Studium, :visible=>true
|
||||
|
||||
@@ -17,6 +17,7 @@ class Beispiel < ActiveRecord::Base
|
||||
acts_as_votable
|
||||
acts_as_flagable
|
||||
belongs_to :lva
|
||||
|
||||
belongs_to :lecturer
|
||||
FLAG_ICONS = {"badquality"=>"fa fa-flag","goodquality"=>"fa fa-flag", "delete"=>"fa fa-trash"}
|
||||
scope :not_flag_badquality, ->{where("flag_badquality IS NULL OR flag_badquality=?",false)}
|
||||
@@ -25,6 +26,9 @@ class Beispiel < ActiveRecord::Base
|
||||
scope :flag_delete, ->{where("flag_delete=?",true)}
|
||||
|
||||
mount_uploader :beispieldatei, AttachmentUploader
|
||||
|
||||
include IsCommentable
|
||||
|
||||
validates :beispieldatei, :presence => true
|
||||
validates :name, :presence => true
|
||||
validates :lva_id, :presence => true
|
||||
|
||||
51
app/models/comment.rb
Normal file
51
app/models/comment.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
class Comment < ActiveRecord::Base
|
||||
attr_accessible :text,:anonym, :intern, :hidden
|
||||
# commentable depth, official, intern, anonym
|
||||
acts_as_votable
|
||||
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
|
||||
belongs_to :commentable, :polymorphic=> true
|
||||
belongs_to :user
|
||||
validate :text, :presence=>true
|
||||
validate :user, :presence=>true
|
||||
validate :commentable, :presence=>true
|
||||
include IsCommentable
|
||||
|
||||
def self.build_for(set_commentable, user, text,attr={})
|
||||
c = new
|
||||
raise "Tried to build comment for non commentable" unless set_commentable.try(:is_commentable?)
|
||||
c.user=user
|
||||
c.text=text
|
||||
c.assign_attributes(attr)
|
||||
|
||||
unless set_commentable.class.to_s == "Comment"
|
||||
c.commentable=set_commentable
|
||||
c.save
|
||||
else
|
||||
|
||||
c.commentable=set_commentable.commentable
|
||||
c.save
|
||||
c.move_to_child_of(set_commentable)
|
||||
end
|
||||
c
|
||||
end
|
||||
def thumb_url
|
||||
t_url= user.fetprofile.picture.thumb.url unless user.nil? or user.fetprofile.nil?
|
||||
t_url
|
||||
end
|
||||
def self.wrapid_for(c)
|
||||
"comments_" + c.class.to_s.gsub(":","_") + "_" + c.id.to_s
|
||||
end
|
||||
|
||||
def self.switchshowid_for(c)
|
||||
"show_comments_" + c.class.to_s.gsub(":","_") + "_" + c.id.to_s
|
||||
end
|
||||
def divid
|
||||
"comment_" + id.to_s
|
||||
end
|
||||
def formid
|
||||
"comment_form_" + commentable_type.gsub(":","_") + "_" + commentable_id.to_s
|
||||
end
|
||||
def self.formid_for(c)
|
||||
"comment_form_" + c.class.to_s.gsub(":","_") + "_" + c.id.to_s
|
||||
end
|
||||
end
|
||||
@@ -3,6 +3,8 @@ class Survey::Question < ActiveRecord::Base
|
||||
belongs_to :parent, polymorphic: true
|
||||
has_many :choices
|
||||
has_many :answers, through: :choices
|
||||
include IsCommentable
|
||||
|
||||
def add_yesno_choices
|
||||
c=Survey::Choice.new(title: "Ja")
|
||||
c.save
|
||||
|
||||
Reference in New Issue
Block a user