You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ActiveAdmin的Volunteer_Details Show页添加返回索引页的链接

解决ActiveAdmin Volunteer_Details Show页面添加返回索引页链接的问题

我明白你的需求——在每条记录的Show视图里加一个直接返回索引页的链接,不用每次点顶部导航。你现在的问题其实是路径助手用错了单数/复数形式:

你写的admin_volunteer_detail_path是指向单个记录的路径助手,它默认会把当前记录的ID(比如你的例子里的4)自动填充进去,所以生成的链接还是指向当前页面。而你需要的是指向索引页的复数版本路径助手:admin_volunteer_details_path(注意末尾的s)。

修正后的代码

把你的show块里的返回链接部分改成下面这样:

show do
  attributes_table do
    row :id
    row 'Name' do |m|
      m.participant.first_name + ' ' + m.participant.last_name
    end
    row :date
    row :importance
    row :story
    row :questions
    row :created_at
    row :updated_at
    row 'Go Back' do
      # 用复数的路径助手,加上按钮样式更贴合ActiveAdmin风格
      link_to 'Back to Volunteer Details Index', admin_volunteer_details_path, class: 'button'
    end
  end
  active_admin_comments
end

额外优化建议

如果觉得把返回链接放在属性表格里不够显眼,你可以把它移到Show页面的顶部,用ActiveAdmin自带的actions块,这样更符合后台操作的习惯:

show do
  # 把返回链接放在页面顶部操作区
  actions do
    link_to 'Back to Volunteer Details Index', admin_volunteer_details_path, class: 'button'
  end

  attributes_table do
    row :id
    row 'Name' do |m|
      m.participant.first_name + ' ' + m.participant.last_name
    end
    row :date
    row :importance
    row :story
    row :questions
    row :created_at
    row :updated_at
  end
  active_admin_comments
end

这样修改后,访问http://localhost:3000/admin/volunteer_details/4时,生成的链接就会正确指向http://localhost:3000/admin/volunteer_details/啦!

内容的提问来源于stack exchange,提问作者dbate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:29:52