I'm using Rails 3.2 and Kaminari for pagination. I'm using the same controller action (index) for rendering all articles and all articles of a specific user. My controller code looks like this:
def index
@articles = (params[:mine] == "true") ? current_user.articles : Article.search(params[:search], :page => params[:page])
respond_to do |format|
format.html
format.json { render json: @articles }
end
end
and in my Article model:
def self.search(search, opts)
if search.present?
where("category LIKE ? OR article_type LIKE ?", "%#{search}%","%#{search}%").page(opts[:page]).per(25)
else
page(opts[:page]).per(25)
end
end
My problem is I do not know how to apply sorting and pagination when showing the current_user's articles. The code for sorting is not yet there by the way. With the current code, I'm having this error 'undefined method `current_page' for #Article' when accessing the index action with the mine parameter set to true.
So my question is how do you apply sorting and pagination when using current_user.articles
? Sample code would really help. Thanks a lot!