Class: Comment

Inherits:
ApplicationRecord show all
Defined in:
app/models/comment.rb

Overview

Comment attached to a state machine Comments can be private (not visible by the requester) -in order to be used for discussing the final decision- or public -allowing two way communication with the requester-.

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes

Instance Attribute Details

#bodyText

Returns:

  • (Text)

Validations:



15
# File 'app/models/comment.rb', line 15

validates :body, :user_id, :machine, presence: true

#created_atDateTime

Returns:

  • (DateTime)


67
# File 'db/schema.rb', line 67

t.datetime "created_at"

#machine_typeString

Returns:

  • (String)


64
# File 'db/schema.rb', line 64

t.string "machine_type"

#privateBoolean

Returns:

  • (Boolean)


69
# File 'db/schema.rb', line 69

t.boolean "private"

#updated_atDateTime

Returns:

  • (DateTime)


68
# File 'db/schema.rb', line 68

t.datetime "updated_at"

#user_idObject (readonly)



15
# File 'app/models/comment.rb', line 15

validates :body, :user_id, :machine, presence: true

Class Method Details

.newest_firstActiveRecord::Relation<Comment>

A relation of Comments that are newest first. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Comment>)

See Also:



24
# File 'app/models/comment.rb', line 24

scope :newest_first, -> { order('created_at desc, id desc') }

.oldest_firstActiveRecord::Relation<Comment>

A relation of Comments that are oldest first. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Comment>)

See Also:



23
# File 'app/models/comment.rb', line 23

scope :oldest_first, -> { order('created_at asc, id asc') }

Instance Method Details

#machineMachine

The associated state machine (request, reimbursement...)

Returns:

  • (Machine)

See Also:

Validations:



11
# File 'app/models/comment.rb', line 11

belongs_to :machine, polymorphic: true, inverse_of: :comments

#public?Boolean

Checks if the comment is public

Returns:

  • (Boolean)

    true is private is false (pretty obvious)



29
30
31
# File 'app/models/comment.rb', line 29

def public?
  !private
end

#userUser

The author of the note

Returns:

See Also:



13
# File 'app/models/comment.rb', line 13

belongs_to :user