Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从RABL中提取分页节点_Ruby On Rails_Pagination_Rabl - Fatal编程技术网

Ruby on rails 从RABL中提取分页节点

Ruby on rails 从RABL中提取分页节点,ruby-on-rails,pagination,rabl,Ruby On Rails,Pagination,Rabl,我使用的是Rails 3.2.18和RABL 0.10.1 现在,我的应用程序中有许多索引操作,包括一些分页信息和集合 呈现的RABL响应示例如下所示: { "current_page" => 1, "total_pages" => 1, "total_count" => 2, "per_page" => 1000, "links" => [ {"id" => ...}, {"id" => ...}] }

我使用的是Rails 3.2.18和RABL 0.10.1

现在,我的应用程序中有许多索引操作,包括一些分页信息和集合

呈现的RABL响应示例如下所示:

{
  "current_page" => 1,
  "total_pages"  => 1,
  "total_count"  => 2,
  "per_page"     => 1000,
  "links"        => [ {"id" => ...}, {"id" => ...}]
}
# config/initializers/rabl.rb
Rabl.configure do |config|
  config.include_child_root = false
end
# app/views/links/index.rabl
object false

node(:current_page) { @links.current_page }
node(:total_pages)  { @links.num_pages }
node(:total_count)  { @links.total_count }
node(:per_page)     { @links.limit_value }

child(@links => :links) do
  extends 'links/show'
end
我的config/initializers/rabl.rb如下所示:

{
  "current_page" => 1,
  "total_pages"  => 1,
  "total_count"  => 2,
  "per_page"     => 1000,
  "links"        => [ {"id" => ...}, {"id" => ...}]
}
# config/initializers/rabl.rb
Rabl.configure do |config|
  config.include_child_root = false
end
# app/views/links/index.rabl
object false

node(:current_page) { @links.current_page }
node(:total_pages)  { @links.num_pages }
node(:total_count)  { @links.total_count }
node(:per_page)     { @links.limit_value }

child(@links => :links) do
  extends 'links/show'
end
下面是上面示例响应的索引视图的外观:

{
  "current_page" => 1,
  "total_pages"  => 1,
  "total_count"  => 2,
  "per_page"     => 1000,
  "links"        => [ {"id" => ...}, {"id" => ...}]
}
# config/initializers/rabl.rb
Rabl.configure do |config|
  config.include_child_root = false
end
# app/views/links/index.rabl
object false

node(:current_page) { @links.current_page }
node(:total_pages)  { @links.num_pages }
node(:total_count)  { @links.total_count }
node(:per_page)     { @links.limit_value }

child(@links => :links) do
  extends 'links/show'
end
我有很多索引操作的当前页面、总页面、总计数、每页节点都是这样构造的。我想减少重复

我希望我能用一个偏音来制作这样的东西:

# app/views/shared/pagination.rabl
node(:current_page) {|o| o.current_page }
node(:total_pages)  {|o| o.num_pages }
node(:total_count)  {|o| o.total_count }
node(:per_page)     {|o| o.limit_value }

# app/views/links/index.rabl
object false

partial 'shared/pagination', object: @links

child(@links => :links) do
  extends 'links/show'
end
但这最终导致了一个错误:

ActionView::Template::Error:
       undefined method `current_page' for #<Link:0x007f92387dbc58>
我已经阅读了RABL文档,并根据我在那里读到的内容尝试了许多其他方法,但我仍然无法找出如何减少重复并保持原始输出

有人知道如何做到这一点吗

谢谢你的帮助,我很乐意提供更多有帮助的信息