[英]Rails4: Will_paginate gem issues
Trying to implement the Will_paginate gem into my rails app, getting error undefined method `paginate' for #. 尝试将Will_paginate gem实施到我的rails应用中,获取#的错误未定义方法`paginate'。 Using gem 'will_paginate', '~> 3.0'
使用宝石'will_paginate','〜> 3.0'
have added the gem to my gemfile and search controller.rb file 已将宝石添加到我的gemfile和搜索controller.rb文件中
class SearchController < ApplicationController
def Home
access_token = ENV["ACCESS_TOKEN"]
client = Instagram.client(access_token: access_token)
default_search = client.tag_search('pizza')
if params[:q]
search_query = client.tag_search(params[:q])
@tag = search_query.present? ? search_query : default_search
else
@tag = default_search
end
@tag = @tag.first.name
@results = client.tag_recent_media(@tag)**.paginate(:page => params[:page], :per_page => 4)**
end
def about
end
end
and added to the home page so it displays the page numbers 并添加到主页,以便显示页码
<form action="?" method="get">
<input type="text" name="q" placeholder="Search Instagram photos..." autofocus/>
</form>
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Welcome //
<small>It's Nice to Meet You!</small>
</h1>
</div>
<div class="row">
<% @results.each do |instagram| %>
<div class="col-md-3">
<%= image_tag instagram.images.low_resolution.url %>
</div>
<% end %>
</div>
<%= will_paginate @results %>
<br/>
will_paginate
only knows how to paginate ActiveRecord queries (and optionally arrays) out of the box. will_paginate
只知道如何直接对ActiveRecord查询(以及可选的数组)进行分页。
It doesn't know how to paginate arbitrary apis though. 它不知道如何分页任意api。 You can use
WillPaginate::Collection
to wrap any data, however it doesn't look like the Instagram api fits very well with this: will paginate assumes that you can skip to an arbitrary offset which you can't with the api. 您可以使用
WillPaginate::Collection
来包装任何数据,但看起来Instagram api不太适合此方法:paginate假定您可以跳至该api无法达到的任意偏移量。 The Instagram api doesn't let you do this - you have to specify the max id and you dont know what that will be other than for the next page of results. Instagram api不允许您执行此操作-您必须指定最大ID,并且不知道下一页结果将是什么。
In short it doesn't really look like you can sensibly use will_paginate
with the Instagram api 简而言之,看起来并不能真正与Instagram api一起使用
will_paginate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.