Singleadmin singleton resource

I would like to create a settings page via activeadmin (change / update). https://github.com/huacnlee/rails-settings-cached .

But I came across the fact that there is no way to register a resource (not resources) in the routes for a particular page, for example, routes such as / admin / settings, but not admin / settings /: id

inherit_resource has

defaults singleton: true

for this case, but it does not work for activeadmin.

Please, help.

Otherwise, I can go with the register_pagse image and create the form myself and update the action, but another problem arose: how can I display error messages on the form from this update action.

A single method is preferred.

+4
source share
1 answer

You can always force an action indexto be redirected to the singleton resource you want. Although this is not an ideal solution, I have used it in the past. Something like that:

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
+2
source

Source: https://habr.com/ru/post/1533391/


All Articles