Skip to content

Commit 4c3e571

Browse files
mauriciopasquierradar
authored andcommitted
Use Kaminari configuration
Fixes rubysherpas#505
1 parent 6178790 commit 4c3e571

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

app/controllers/forem/application_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ def current_ability
99
Forem::Ability.new(forem_user)
1010
end
1111

12+
# Kaminari defaults page_method_name to :page, will_paginate always uses
13+
# :page
14+
def pagination_method
15+
defined?(Kaminari) ? Kaminari.config.page_method_name : :page
16+
end
17+
18+
# Kaminari defaults param_name to :page, will_paginate always uses :page
19+
def pagination_param
20+
defined?(Kaminari) ? Kaminari.config.param_name : :page
21+
end
22+
helper_method :pagination_param
23+
1224
private
1325

1426
def authenticate_forem_user

app/controllers/forem/forums_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def show
1717
@forum.topics.visible.approved_or_pending_review_for(forem_user)
1818
end
1919

20-
@topics = @topics.by_pinned_or_most_recent_post.page(params[:page]).per(Forem.per_page)
20+
@topics = @topics.by_pinned_or_most_recent_post
21+
22+
# Kaminari allows to configure the method and param used
23+
@topics = @topics.send(pagination_method, params[pagination_param]).per(Forem.per_page)
2124

2225
respond_to do |format|
2326
format.html

app/controllers/forem/posts_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ def authorize_reply_for_topic!
5757
def authorize_edit_post_for_forum!
5858
authorize! :edit_post, @topic.forum
5959
end
60-
60+
6161
def authorize_destroy_post_for_forum!
6262
authorize! :destroy_post, @topic.forum
6363
end
6464

6565
def create_successful
6666
flash[:notice] = t("forem.post.created")
67-
redirect_to forum_topic_url(@topic.forum, @topic, :page => @topic.last_page)
67+
redirect_to forum_topic_url(@topic.forum, @topic, pagination_param => @topic.last_page)
6868
end
6969

7070
def create_failed

app/controllers/forem/topics_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class TopicsController < Forem::ApplicationController
88
def show
99
if find_topic
1010
register_view(@topic, forem_user)
11-
@posts = find_posts(@topic).page(params[:page]).per(Forem.per_page)
11+
@posts = find_posts(@topic)
12+
13+
# Kaminari allows to configure the method and param used
14+
@posts = @posts.send(pagination_method, params[pagination_param]).per(Forem.per_page)
1215
end
1316
end
1417

app/helpers/forem/topics_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module TopicsHelper
33
def link_to_latest_post(topic)
44
post = relevant_posts(topic).last
55
text = "#{time_ago_in_words(post.created_at)} #{t("ago_by")} #{post.user}"
6-
link_to text, forem.forum_topic_path(post.topic.forum, post.topic, :anchor => "post-#{post.id}", :page => topic.last_page)
6+
link_to text, forem.forum_topic_path(post.topic.forum, post.topic, :anchor => "post-#{post.id}", pagination_param => topic.last_page)
77
end
88

99
def new_since_last_view_text(topic)

0 commit comments

Comments
 (0)