集合不是分页作用域.在调用:paginated_collection之前,设置collection.page(param



我的Rails应用程序运行良好,突然出现以下错误:Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection

这是我的Course型号的代码:

# 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

这是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

这个错误的原因可能是什么?

我发现了问题。

在我的ApplicationController中,我声明了一个与CourseController中现有变量冲突的变量,所以我通过更改变量名来修复它。

最新更新