Voxd
Voxd

Reputation: 49

Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection

My Rails application was working just fine, when suddenly I started getting the following error: Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.

Here's the code of my Course model:

# app/models/course.rb
class Course < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, use: [:slugged, :finders]

  has_many :steps

  has_many :subscriptions
  has_many :users, through: :subscriptions

  has_many :reviews

  validates :name, presence: true, length: { maximum: 50 }
  validates :content, presence: true, length: { maximum: 500 }
  validates :price, presence: true, numericality: { only_integer: true }

  has_attached_file :image, :styles => { :medium => "680x300>", :thumb => "128x118>" }
  validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

  def average_rating
    reviews.blank? ? 0 : reviews.average(:star).round(2)
  end

  def price_in_cents
    price * 100
  end
end

And here's the code in app/admin/course.rb:

ActiveAdmin.register Course do
  permit_params :name, :content, :price, :image, :slug

  show do |t|
    attributes_table do
      row :name
      row :content
      row :price
      row :slug
      row :image do
        course.image? ? image_tag(course.image.url, height: '100') : content_tag(:span, "No photo yet")
      end
    end
  end

  form :html => { :enctype => "multipart/form-data" } do |f|
    f.inputs do
      f.input :name
      f.input :content
      f.input :price
      f.input :slug
      f.input :image, hint: f.course.image? ? image_tag(course.image.url, height: '100') : content_tag(:span, "Upload JPG/PNG/GIF image")
    end
    f.actions
  end
end

What could be the cause for this error?

Upvotes: 1

Views: 1845

Answers (1)

Voxd
Voxd

Reputation: 49

I found the problem.

In my ApplicationController I had declared a variable that was conflicting with an existing variable in my CourseController, so I fixed it by changing the variable name.

Upvotes: 1

Related Questions