0
  • 导轨 3.2.13
  • 红宝石 1.9.3

嗨,我正在添加下一个和上一个网址以获得最佳 SEO 结果。但我意识到我的服务器日志中有 2 个页面请求(当前页面和下一页)。

这是我的控制器的一部分:

@recipes = Recipe.includes(:chef, :category).order("created_at desc").page(params[:page]).per(9)

if @recipes.present? == true
   if @recipes.first_page? && @recipes.num_pages > 1
      ...
      @next_url = url_for(:page => (@recipes.current_page + 1))
      ...
   end
   ...
end

但是当调用@next_url 时,整个页面都会被请求。我只想将 1 与当前的 url 字符串相加。

我该如何解决这个问题?

更新:

问题是 MAC 上的 Firefox (21.0)。在其他浏览器中,此请求不会发生。浏览器运行不好!我无法修复它,不幸的是!

4

1 回答 1

0

First of all, I need to point out that

if @recipes.present? == true

is not a good coding practice, since @recipes.present? will actually return true or false

what you want to achieve with this piece of code?

  if @recipes.first_page? && @recipes.num_pages > 1
      ...
      @next_url = url_for(:page => (@recipes.current_page + 1))
      ...
   end

so if it is first page and the page number is greater than 1 then there will have @next_url?

should be OR || ,is it? can you explain what you trying to do?

于 2013-05-21T15:05:28.450 回答