【问题标题】:activeadmin singleton resourceactiveadmin 单例资源
【发布时间】:2014-03-25 19:02:29
【问题描述】:

我想通过 activeadmin(编辑/更新)创建设置页面。 https://github.com/huacnlee/rails-settings-cached.

但我遇到了无法在特定页面的路由中注册资源(不是资源)的问题,例如有 /admin/settings 之类的路由,但没有 admin/settings/:id

inherit_resource 有

defaults singleton: true

对于这种情况,但这不适用于 activeadmin。

请帮忙。

否则,我可以使用 register_pagse 方式并自己创建表单并更新操作,但出现了另一个问题:如何通过该更新操作在表单上呈现错误消息。

单例方式是首选。

【问题讨论】:

    标签: ruby-on-rails ruby activeadmin inherited-resources


    【解决方案1】:

    您始终可以强制 index 操作重定向到您想要的单例资源。虽然这不是一个完美的解决方案,但我过去曾使用过它。像这样的:

    ActiveAdmin.register Setting, as: 'Setting' do
    
      actions :all, only: [:show, :edit, :update, :index]
    
      controller do
    
        def index
          redirect_to resource_path(Setting.first)
        end
    
      end
    
    end
    

    【讨论】:

      猜你喜欢
      • 2013-10-16
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多