ActiveAdmin添加按钮“上一个”

时间:2014-08-10 10:57:25

标签: ruby-on-rails ruby activeadmin

我正在尝试将两个按钮“previous”,“next”添加到ActiveAdmin显示页面。

action_item only:[:show] do |recipe|
    link_to "Previous", admin_recipe_path(Recipe.where(["id > ?", recipe.id]).first)
end

这将导致

No route matches {:action=>"show", :controller=>"admin/recipes", :id=>nil} missing required keys: [:id]

如果我在admin_recipe_path中添加.id,则会显示undefined method ``id' for nil:NilClass

1 个答案:

答案 0 :(得分:1)

我能解决这个问题......

action_item only: :show do
  id = Recipe.where('id < ?', recipe.id).order('id DESC').first
  link_to 'Previous', admin_recipe_path(id: id)
end