Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activeadmin singleton resource

i'd like to create settings page via activeadmin (edit/update). https://github.com/huacnlee/rails-settings-cached.

But i faced that there is no way to register resource (not resources) in routes for particular page, eg have routes like /admin/settings, but not admin/settings/:id

inherit_resource has

defaults singleton: true

for this case, but this doesnt work for activeadmin.

Please help.

Otherwise, i can go with register_pagse way and create form myself and update action,but another problem appeared: how can i render errors messages on form from that update action.

The singleton way is way preferred.

like image 386
Kirill Salykin Avatar asked Oct 20 '22 11:10

Kirill Salykin


1 Answers

You can always force the index action to redirect to the singleton resource that you want. While this is not a perfect solution, I have used it in the past. Something like this:

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
like image 200
Kevin English Avatar answered Oct 23 '22 00:10

Kevin English