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:
The AppConfig
has one database field per setting, so it looks something like this:
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:
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.