app/models/post.rb
# Returns page this post is on (on posts index page).
Returns page this post is on (on posts index page).
Returns page this post is on ( on posts index page ) .
def page
    count = topic.posts.count
    index = topic.posts.to_a.index(self) + 1
    per_page = KmForum::POSTS_PER_PAGE
    if count < per_page
      nil
    elsif (index % per_page).zero?
      index / per_page
    else
      index / per_page + 1
    end
  end
def page count = topic . posts . count index = topic . posts . to_a . index ( self ) + 1 per_page = KmForum :: POSTS_PER_PAGE if count < per_page nil elsif ( index % per_page ) . zero? index / per_page else index / per_page + 1 end end
Returns page this post is on (on posts index page).
Returns page this post is on ( on posts index page ) .
# If there are less posts than per_page limit then last page is first page # In such case we have to pass nil as a page because in other case we get # unexpected behavior.