集合不是分页范围。在调用之前设置collection.page(params [:page])。per(10):paginated_collection

时间:2015-07-19 12:30:46

标签: ruby-on-rails ruby-on-rails-4 activeadmin

My 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

导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:1)

我发现了问题。

在我的<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <a href="javascript:void(0)" id="view-large" data="p1010352.jpg">View</a> <div class="blog-image-view"></div> <img id='demo' src=''/>我声明了一个与我def getchfunc(): import termios import sys, tty if sys.stdin.isatty(): def _getch(): fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(fd) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch else: def _getch(): return sys.stdin.read(1) return _getch 中的现有变量冲突的变量,所以我通过更改变量名来修复它。