Rails & Bootstrap & Font Awesome

Today was productive. I was able to create a more in-depth TODO file during the day while I was watching my kiddos. This allowed me to think more about how my app was going to function and what I needed/wanted to build into it. It provided me with a better workflow for the evening. I knew exactly what I would be working on tonight. Even if I did get sidetracked a couple times while working it was still always productive. Granted a lot is going into making the app look better than a default Bootstrap install. I got Omniauth through Devise up and running tonight smoothly by following the docs. The only snag I hit for a quick minute was in my using of dotenv.

# First try
config.omniauth :facebook, FB_APP_ID, FB_APP_SECRET

# Second try
config.omniauth :facebook, 'FB_APP_ID', 'FB_APP_SECRET'

# Third and correct try
config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET']

This was pretty easy to troubleshoot. The first try threw an error. The second try had FB_APP_ID in my Oauth URL telling me that the string was being passed (makes sense). Then one more reading of the docs and I got the correct implementation.

I also had to figure out how to render a proper looking Bootstrap button as a link using Rails helpers. Okay, I didn’t have to but I wanted to. After playing around for a bit I decided on this code:
<%= button_to 'Add Your First Place', new_place_path, class: 'btn btn-primary', method: :get %>
Which isn’t the prettiest but is getting the job done correctly. I want to add a Font Awesome icon inside the button and I think to do that I’ll have to pass a block in. I’m going to work on that tomorrow though. It’ll be a useful thing to figure out so I can stylize the OAuth login buttons better. The one I have right now is currently just a text link. We all know that’s no fun.

I also went to a meetup tonight where the presenter talked about Elm. It’s a functional language which is definitely different. However, the presenter said that he felt Elm was a great starter to learn a functional language. I’ll probably look into this when I finally have some free time after I’m done with Flatiron. Elixir is of interest but it might be too big of a jump to start. We’ll see. I could possibly also keep building things in the languages I’m learning to show more mastery of those until I land my first gig then start branching off. Another one out there is Hanami built on Ruby which I’ve heard is pretty cool and built more like other frameworks and libraries than Rails. That might be the next logical step. There’s just so much knowing what to do next is a research project in its own right. I look forward to it though.

My newest obsession which I learned at the meetup tonight is leading commas:

new_person = { name: "Seth"
  , age: 32
  , height: 74
  , weight: 155
  , alive: true
}

I’ll just leave that there.

Time spent today: 2:19
Time spent total: 306:57
Lessons completed today: 0
Lessons completed total: 518

I Think I Can, I Think I Can…

Man, it’s hard keeping track of all the tools I’m using as I’m building out this app. I’m finding the biggest thing I’m focusing on right now is getting Devise to look nice by customizing the views and implementing Bootstrap 4. One thing I had to work on was updating the strong params in Devise so my User could register with a name. That wasn’t too tricky although I’m implementing it “the lazy way™” which I’m okay with for now.

I also updated my messages with a better implementation from the Devise docs here. The one thing that didn’t take into account is that when implementing the Bootstrap 4 gem docs specifically say:

Then, remove all the *= require and *= require_tree statements from the Sass file. Instead, use @import to import Sass files.

Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins and variables.

So my custom.css.scss was not loading. A quick tour of the Asset Pipeline and I got it working. However, now looking back and writing this I need to utilize @import instead of how I did it using *= require custom.css.scss in my application.scss file. Boom done.

@import "custom.css.scss";
@import "bootstrap";

I’ve accomplished more than I thought I had when I went through the spec provided by Flatiron and started checking things off. I think I can still be finished by Sunday night. I actually think it’s not as hard as I was making it fulfill the requirements. Considering the things they’ve taught us I would expect there to be some sort of roles integration or something but there wasn’t. I do want to build something that utilizes Pundit, however, this app isn’t the right fit for that. I’ll figure something out so I have some things to do when I’m done with the program while I job search.

Okay, it’s late. Until tomorrow.

Time spent today: 3:01
Time spent total: 304:38
Lessons completed today: 0
Lessons completed total: 518

Rails Project is Underway

I didn’t get much done yesterday so I ended up not writing. I did figure out an app to build for my project. However, I wasn’t able to get much done in the way of getting started. I won’t get into it, but, I was frustrated with last night.

Tonight has been better. I’m making progress setting the base of the app up. It took a little bit to figure out how to setup PostgreSQL. I’m not sure I could tell anybody else how to do it but I got it working. I did this because when I deploy I plan to have my app on Heroku. Heroku doesn’t support SQLite but does support PostgreSQL. I figured this would save deployment headaches. We’ll see. I think I have all the gems I’ll need, except Devise Omniauth stuff. I figured I can have that on a TODO for later. Or even after I pass my assessment. I’ve started keeping my TODO though which is good. I’ll be able to better keep track of the things I want to implement even if I don’t do it for my assessment. I also got Bootstrap 4 loaded up and ready so I can make everything prettier when I’m done.

I’m trying to be more organized in how I keep track of things and plan my projects. I know as they get more complex this will be an important step. Hence, the DB wireframe I did. It’s not super complex but I’m going to fill it out more than I did with my Sinatra project.

I have an idea for another app and will have to decide when to build that out. I don’t think it would have hit all the requirements for this project so I didn’t want to start it then have to force it so to speak to get it to fit. So what am I building? Basically a personal review site for food and beverage items. You’ll be able to keep track of things you like and dislike at places.

Random side note. I downloaded Opera again for the first time in forever after reading “Friendship Ended With CHROME Now OPERA Is My Best Friend”. Specifically the fact that Opera is built on the same engine as Chrome, Blink. Thus it renders pages almost the exact same way. In fact, it even has the same keyboard shortcuts (as far as I can tell) and dev tools.

Time spent today: 3:30
Time spent total: 301:37
Lessons completed today: 0
Lessons completed total: 518

Rails Project Here I Come

I’m officially ready to start my Rails Portfolio Project! Woot woot! I still don’t know what I’m going to do for it so I’m going to read the requirements tonight and brainstorm through the day tomorrow so I can start tomorrow night. I’ll also bring this up in the weekly stand up tomorrow morning and see if I can get some ideas.

I had a couple unique problems today, at least unique to me. I was working on a project all day and it’s an eCommerce store. The idea was that a User would have a Cart and you could get the cart for the User by calling current_cart. I initially created a setter and getter. However, this quickly broke down as I worked through all the tests. I was banging my head against the wall so I did some looking and ended up adding a new association to my User model.

has_one :current_cart, class_name: "Cart"

While I had implemented this before in other labs/lessons this time it clicked. The User will have one cart (makes sense) and it will be of the class Cart. So current_cart works like an alias for carts with the User model since a User has_many :carts. User.carts and User.current_cart do the same thing as far as I can tell.

Another method that hadn’t completely clicked until this project was try(). I had read the documentation on it but never implemented it. Then I hit a snag where I was raising a NoMethod error because of a nil in an if statement. I thought to myself, “This is obviously false if it’s nil.” Then the lightbulb went off. This is exactly what try() is used for. Instead of raising an error when a method is being called on nil it’ll just return nil which in turn evaluates to false. I even called it inside of an attribute which I felt accomplished by even if it’s not that big of a deal in reality.

line_item = line_items.find_by(item_id: itemid)
    if items.include?(line_item.try(:item))

I also kept up with my commit messages on this project. You can check out the finished project here. It was nice to not have to build out all the views for this. While it’s good to practice it has felt monotonous and unproductive building so many views during lessons. Especially when learning how to implement things like authentication and ending up spending more time rendering info from the DB in views than what the lesson was teaching.

I’m looking forward to hitting the ground running tomorrow night with a solid idea and getting all my migrations that I think I’ll need done as well as getting the app initialized. RubyMine has a way to start a new Rails project and I’m going to compare what that creates to what rails new project-name creates.

It’s kind of crazy to think how far I’ve come to this point. I remember when I started I would look at people’s profiles with 500+ “Number of Lessons Completed” and think about how much they must know. Or wonder how long it had taken them to get that far. Now I’m right there too.

I just realized it’s past 1am. I got sidetracked starting to think about my Rails project and if I want to implement TDD or not. It would look good but do I want to spend the time now or later? Granted, the whole idea behind TDD is writing the tests FIRST. However, even writing them after to just get the experience should be valuable too at this point in my learning.

Time spent today: 5:02
Time spent total: 296:54
Lessons completed today: 2
Lessons completed total: 518

Rails Projects & RubyMine

Today was long but good. I started off by hosting my first study group. Turns some people really do get some coding done on the weekends even if Slack is much quieter. We had a good talk and it was an easy way to start the day.

I got through the Pundit lab which took way longer than I thought it would but that was fine. I didn’t feel like I was beating my head against a well. Just progressing. It felt good to struggle some then overcome.

I started my first Rails Project tonight and was able to get all of the model tests passing. I’ve completely (except for this blog) switched over to RubyMine now and I’m slowing figuring out more and more about it. It’s super powerful and I see a lot of it relies on opening a project in the root folder. All of the labs for Flatiron are in a singular folder so I typically open that one folder full of folders and that throws off most of the features of RubyMine. Too many VCS repos all in one project. Tonight I got tests to run automatically upon code changes. I also realized that RubyMine could generate an image with relationships mapped for my models which is dope. In addition, I started to look at the rubocop linting and was able to remove the block from this map method and use &: instead.

# before
def total
  items.map { |item| item.price }.sum
end

# after rubocop linting
def total
  items.map(&:price).sum
end

I also decided to track my time on each project from now on. However, I completely forgot to start tracking my Rails Projects when I got to it though. Luckily Wakatime saved the day and told me how long I had been working on the project. I’m stoked that I’m on the projects even if it’s a little later in the day than I had planned on. This means I’m almost 100% going to be starting my Rails Portfolio Project tomorrow!

Time spent today: 10:26
Time spent total: 291:53
Lessons completed today: 2
Lessons completed total: 516

Useful or Not?

So last night I chose not to write a post. I attended a study group that walked through the lab I’ll be doing tomorrow on Pundit and watched a lecture. Since I didn’t do any actual writing of code I skipped the blog. However, I know how to solve the Pundit lab quickly now ;-).

I started tonight off helping out my man Mike (we did the Music Library CLI project together) set up his associations for this Sinatra portfolio project (see above). That was fun and I realized I knew how to explain to somebody else associations.

The rest of tonight was all about CanCanCan and Devise Roles. CanCanCan was a pain in the ass, to say the least. The Devise Roles labs had very little coding related to roles and the tests were more about the controllers and views. I have an intuition of sorts and know when to “phone it in” sometimes. Tonight I did that on CanCanCan. I didn’t really understand it and just kept going anyway. I chose not to dive deep into it. Later on tonight in a lecture video Avi stated that he doesn’t use CanCanCan. I guess it’s supposed to be like the SQL before Active Record. I just have a hard time wrapping my head around getting taught a gem that isn’t recommended. Either way, I’m past it now.

I’m leading my first study group in the morning. Wish me luck!

Time spent today: 4:40
Time spent total: 281:27
Lessons completed today: 5
Lessons completed total: 514

CanCanCan? I Thought It Was Can Can?

I spent a lot of time yesterday and today psyching myself out about this Devise lab. Turns out it was very straightforward. All the extra “research” I was doing was actually taking away from me getting it done. When I reset myself and approached the lab like all the others I got through it quickly.

  1. Follow ReadMe.
  2. Run tests.
  3. Look at the spec for the first test.
  4. Get the first test to pass.
  5. Repeat 2-4 until all tests pass.

That’s what I should have done from the beginning but I had the nagging little voice from my SG last week and this week that I was being hung out to learn the hard way on this one. Now, I’m working on a CanCanCan lab which doesn’t seem to be too difficult but after that is a Devise Roles lab. Maybe that’s the one everybody has been telling me about. Or maybe this stuff really does click in my head. I dunno. Either way, I’m feeling good making progress again today. I wish I hadn’t spent so much time on other stuff though because I’d probably be passed this CanCanCan lab already.

Time spent today: 1:53
Time spent total: 273:42
Lessons completed today: 2
Lessons completed total: 509