0

Although I'm working with Rails for 10 years now, the routing conventions and mechanisms still are something I don't really see through.

So I have created a singleton resource AppConfig where admins can maintain some global settings for my app:

Screenshot of the admin area

The AppConfig has one database field per setting, so it looks something like this:

Screenshot of database tool

As the app only needs one single AppConfig record, I've implemented some mechanism to retrieve it through AppConfig.instance (or create such a record when none is available), inspired by See How to implement a singleton model:

def self.instance
  first_or_create! app_abbreviation: 'A4AA 2.0',
                   app_name: 'Access for All Audit 2.0',
                   app_slogan_de: 'Accessibility Audit Tool der nächsten Generation',
                   app_slogan_en: 'Next generation accessibility audit tool',
                   organisation_name_de: '«Zugang für alle»',
                   organisation_name_en: '«Access for all»',
                   organisation_abbreviation_de: 'ZFA',
                   organisation_abbreviation_en: 'A4A',
                   organisation_url: 'http://www.access-for-all.ch/'
end

def self.find(*args)
  instance
end

And I've added a route like this:

resources :app_configs, only: [:show, :edit, :update]

Everything works very well, but I'm bugged by the ID in the URL:

Screenshot of browser URL

Is there a way to hide it, and simply have /en/app_configs (pointing to #show) and /en/app_configs/edit? I fiddled around with resource (instead of resources) but I seem to have trouble getting it to work.

Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152
  • `resource` would be the best way probably, what doesn't seem to be working with that? – Eyeslandic Dec 11 '20 at 08:56
  • 1
    I second @Eyeslandic. `resource` is exactly what you are looking for. That or you can just define the routes your self e.g. `get 'app_configs', to: 'app_configs#show', as: :app_config; get 'app_configs/edit, to: 'app_configs#edit', as: edit_app_config; put 'app_configs', to: 'app_configs#update'` – engineersmnky Dec 11 '20 at 13:59

0 Answers0