Submitted almost 3 years ago
(3pm - 6:30pm)
* Fixed issue where user profiles wouldn't load because part of my app was still looking in the browser session for the user's id rather than the user's slug
* Added reference from budgets table to user slug so that budgets could display in user profile
* Determined source in code of why it isn't possible to create new budgets, but need to determine cause
* Made it so that I don't have to press 3 keys on my at-home keyboard just to type a backtick
* I've also made it to exactly 13 hours for my #144HoursOfCode, which is 9% complete with the challenge total and 1 hour more than I planned to code for the week.
Changing what displays to identify a user in the browser from the id to the user slug created plenty of work for me!
The last piece of the puzzle that was looking for the user id in the browser session turned out to be the
User.find method itself, with the format
User.find(params[:slug]) being the issue. Once I changed that to
User.find_by_slug(params[:slug]) I found that the profile lookup was working properly. To help me verify that it was the users profile #show action that was causing the issue, I installed the lograge gem to help me (in server logs, specifically) on the recommendation of this article.
Next the user profile didn't want to load because it displays a user's budgets, and the budgets were also being looked up based on the user's id rather than the user's slug. To fix that, I added a reference via foreign key to the budgets table that referenced the user slug. The process I used contained more steps than necessary since I didn't have a great idea of what I was doing, so that's definitely something I need to learn more about. I used these resources to help me with that process:
Those two steps got the user profile loading, but the next problem I ran into was that creating a new budget didn't work - I got the error "User must exist." I found that removing the
belongs_to :user, foreign_key: 'user_slug'validation on the budget model allowed me to successfully create a new budget, but as one might expect it didn't have a user id or user slug associated with it (so I added them via the console). Next step for me is to determine why this is the source of the issue.
As for fixing the backtick on the keyboard I use at home, I spent more time than intended on that detour. The keyboard I use has a key that escape, backtick, and tilde all share. I use escape often because I edit in Vim, and backtick often in Slack and markdown to indicate code blocks. To use backtick on this keyboard, I was having to type 3 keys but now I've got it to a much more manageable two-key combination (escape still takes precedence for the key because I use it so frequently in Vim). I used Karabiner-elements to remap the keys, but I had to edit a .json file to do it and it took me quite a few tries and plenty of JSON linting to get it right. In addition to getting my syntax right, I had to be sure to add my settings for the correct device, profile, and figure out whether it should be a "simple modification" or "complex modification." Phew! Glad I don't have to do that again. I'm going to go ahead and commit that file to github for safekeeping.
Here's today's commit:
Update: I went ahead and pushed up all my latest dev environment/dotfile changes as mentioned above: https://github.com/twoesplease/dev_environment/commit/20cfad4521da9b8805abc88e5975f82bf86e4688