我无法让 will_paginate 在我正在创建的 pinterest 风格的 Rails 应用程序上工作。我一直在关注 will_paginate railscast。我从这一行得到一个错误:编辑:这是我得到的错误:
NoMethodError in PinsController#index
undefined method `page' for "created_at desc":String
Rails.root: /Users etc....
Application Trace | Framework Trace | Full Trace
app/controllers/pins_controller.rb:6:in `index'
到目前为止,我将 will_paginate 添加到我的 gemfile 并运行 bundle :
这是我的 Gemfile:
gem 'rails', '3.2.11'
gem 'jquery-rails
gem 'devise'
gem 'simple_form'
gem "paperclip", "~> 3.0"
gem 'aws-sdk'
gem 'will_paginate', '> 3.0'
gem 'bootstrap-will_paginate', '0.0.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'bootstrap-sass', '~> 2.3.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
这是我的 pins_controller.rb (我得到我的错误):
class PinsController < ApplicationController
before_filter :authenticate_user!, except: [:index]
# GET /pins
# GET /pins.json
def index
@pins = Pin.order("created_at desc").page(params[:page]).per_page(5)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @pins }
end
end
这是我的 index.html.erb :
<%= render 'pages/home' %>
<div id="pins">
<%= render @pins %>
<%= will_paginate @pins %>
</div>
如果你想看看在我开始玩 will_paginate 之前我一直在做什么,你可以在我的 github repo 上看到我的代码。我是发布问题的新手,但在这里搜索没有找到任何东西,并尝试遵循最佳实践。谢谢你的帮助。