【问题标题】:Error with pagination while using rpsec使用 rpsec 时分页出错
【发布时间】:2012-12-22 02:27:18
【问题描述】:

我在 Micheal Hartl 教程第 9 章上。我正在尝试检查用户名是否显示在页面上。但我收到了这个错误

Failure/Error: User.paginate.(page:1).each do |user|
     ArgumentError:
       wrong number of arguments (0 for 1)

我可能要更改这部分 User.paginate.(page: 1).each do |user|。但是我该怎么办?

这里是 rspect 目录中的代码。

describe "index" do

    let(:user) { FactoryGirl.create(:user) }

    before do
        sign_in user 
        30.times { FactoryGirl.create(:user) }
        visit users_path
    end

    it { should have_selector('title', text: 'All users') }
    it { should have_selector('h1',    text: 'All users') }

    it "should list each user" do
      User.paginate.(page: 1).each do |user|
        page.should have_selector('li>a', text: user.name )
      end
    end
  end

【问题讨论】:

  • 你使用的是什么版本的 ruby​​?
  • 您的 Gemfile 中有 will_paginate gem 吗?
  • 是的 gem 'will_paginate', '3.0.3'

标签: ruby-on-rails ruby-on-rails-3 rspec pagination railstutorial.org


【解决方案1】:

分页后有一个额外的时间段。应该是:

    User.paginate(page: 1).each

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 2015-10-19
    • 2014-12-20
    相关资源
    最近更新 更多