Class: Formol::ApplicationController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/formol/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#last_page_forum_topic_path(forum, topic, post) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/formol/application_controller.rb', line 33

def last_page_forum_topic_path(forum, topic, post)
  opts = {
    :anchor => "formol_post_#{post.id}"
  }
  
  page = topic_last_page_number(topic)
  
  opts[:page] = page if page > 1
  
  forum_topic_path(forum, topic, opts)
end

#paginated_forum_topic_post_path(forum, topic, post) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/formol/application_controller.rb', line 15

def paginated_forum_topic_post_path(forum, topic, post)
  opts = {
    :anchor => "formol_post_#{post.id}"
  }
  
  page = topic_post_page_number(topic, post)
  
  opts[:page] = page if page > 1
  
  forum_topic_path(forum, topic, opts)
end

#per_pageObject



3
4
5
# File 'app/controllers/formol/application_controller.rb', line 3

def per_page
  25
end

#topic_last_page_number(topic) ⇒ Object



29
30
31
# File 'app/controllers/formol/application_controller.rb', line 29

def topic_last_page_number(topic)
  (topic.posts_count.to_f / per_page.to_f).ceil
end

#topic_post_page_number(topic, post) ⇒ Object



10
11
12
13
# File 'app/controllers/formol/application_controller.rb', line 10

def topic_post_page_number(topic, post)
  #topic.posts.index is maybe not the most optimized
  ((topic.posts(true).index(post) + 1).to_f / per_page.to_f).ceil
end