【发布时间】:2015-02-24 02:55:39
【问题描述】:
我在 ruby 应用程序中使用 will_paginate gem,并且在大多数情况下它工作正常。但是当我没有用户登录时,我遇到了麻烦。
该应用是 reddit 类型的东西,有主题和相关的帖子和 cmets。
在我的主题模型中,我有以下内容:
class Topic < ActiveRecord::Base
has_many :posts, dependent: :destroy
scope :visible_to, -> (user) {user ? all : :publicly_viewable}
scope :publicly_viewable, -> {where(public: true)}
scope :privately_viewable, -> {where(public: false)}
end
在我的主题控制器中:
class TopicsController < ApplicationController
require 'will_paginate/array'
def index
@topics = Topic.visible_to(current_user).paginate(page: params[:page], per_page: 10)
authorize @topics
end
当我点击没有 current_user 的主题链接时,据我了解,模型中的“用户”应该返回 nil,这应该是一个功能记录。只应返回public_viewable 主题。但我收到以下错误消息:
undefined method `paginate' for :publicly_viewable:Symbol
我想也许我正在处理一个数组,所以我添加了“require 'will_paginate/array'”,但这没有帮助。
有人有什么想法吗?
谢谢。
【问题讨论】:
标签: ruby-on-rails will-paginate