Class: Topic

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/topic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



20
21
22
# File 'app/models/topic.rb', line 20

def body
  @body
end

Instance Method Details

#editable_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/topic.rb', line 42

def editable_by?(user)
  user && (user.id == user_id) 
end

#hit!Object



22
23
24
# File 'app/models/topic.rb', line 22

def hit!
  self.class.increment_counter :hits, id
end

#last_pageObject



38
39
40
# File 'app/models/topic.rb', line 38

def last_page
  [(posts_count.to_f / Post.per_page).ceil.to_i, 1].max
end

#paged?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/topic.rb', line 34

def paged?
  posts_count > Post.per_page
end

#sticky?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/topic.rb', line 26

def sticky?
  sticky == 1
end

#update_cached_post_fields(post) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'app/models/topic.rb', line 46

def update_cached_post_fields(post)
  # these fields are not accessible to mass assignment
  remaining_post = post.frozen? ? recent_post : post
  if remaining_post
    self.class.update_all(['replied_at = ?, replied_by = ?, last_post_id = ?, posts_count = ?', 
      remaining_post.created_at, remaining_post.user_id, remaining_post.id, posts.count], ['id = ?', id])
  else
    self.destroy
  end
end

#viewsObject



30
31
32
# File 'app/models/topic.rb', line 30

def views
  hits
end