module Formol class ApplicationController < ::ApplicationController def per_page 25 end helper_method :per_page helper_method :current_formol_user 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 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 helper_method :paginated_forum_topic_post_path def topic_last_page_number(topic) (topic.posts_count.to_f / per_page.to_f).ceil end 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 helper_method :last_page_forum_topic_path end end