"But wait, there's more"

Posted by Denny at 18:48 on Sat, 19 Oct 2019

While I was feeling on top of the world thanks to the `accepts_nested_attributes_for` win, I managed to get two more PRs written and merged on the same day... one a new feature, one some refactoring and structural improvements. (It's not as impressive as it sounds - the nested attributes PR was merged an hour or so after midnight, so there was plenty of day left to me) :)

So; rather later in the morning I merged allow username logins as well as email logins, which extends and configures Devise to allow people to log in using a username or their email address (Devise only supports using the email address as the user login by default). I pulled this together from a few different blog posts which I'm not going to link, because each of them was wrong in a different place, and/or for an ancient and half-obselete version of Devise - but between the contradictory sets of code and other clues I somehow managed to cobble together something that worked eventually.

(ETA: Pride cometh before the fall. If you decide to use a copy of the aforementioned working code in your own project, ignore the last PR of today, where I removed some of the user login method because my tests showed it as unused. What I should have done was write more tests to exercise that code :) I ended up having to put it back in eventually!)

And then this evening, I merged Helpers and Concerns and Elements, oh my! which collected some useful methods for generating menus into a helper, and some common behaviour for element models into a concern (templates and templated content have elements, and those two categories will contain a few different types of object eventually - pages and their templates, newsletters and their templates, etc). As well as keeping me DRY, it occurs to me that if a lot of common behavior for 'The ShinyCMS Way' is eventually defined by a collection of helpers and concerns, that should make it easier for anybody who wants to add a new feature to do it in a way that behaves similarly to the existing features - which should work out better for other developers (including me!) who might want to work on that code, and for the end-users of the new feature too.

Tags: devise users logins usernames elements helpers concerns structure

« Top-level slug validation Sufficiently advanced technology... »


No comments found