When you’ve been deeply focused on a big project or a new job, you might poke your head up and feel lost. Like the tech world has moved beyond you. Did that time you didn’t spend learning new things finally catch up with you? And how can you close that gap? Study at home? Or learn at work? If you…
Justin Weiss
https://www.justinweiss.com/articles/archives/ · 20 posts · history since 2015 · active
1 May 2019
22 Aug 2017
Maybe fixing a bug just spawned a dozen new ones. Or your code breaks in such a weird way that you wonder if you really understand it at all. You think it’s time for a deep dive. But knowing you need to dive deeply into a topic? That’s only step 1. How do you actually learn a topic down to…
15 Aug 2017
Have you ever found a Rails topic that didn’t make any sense to you? Like, you thought you knew it, so you wrote some code, and something completely different happened? Or you know you don’t understand, but you kind of know enough to get by, except you spend so much time fighting edge cases that you could have been an…
9 May 2017
In my most recent article, I mentioned a great new feature in Rails 5.1, delegate_missing_to. With delegate_missing_to, any method that you can’t find on one object is called on another object, instead: class Player delegate_missing_to :@user def initalize(user) @user = user end def points Game.points_for_user(user.id) end end Player.new(user).name # calls user.name But, like Gavin mentioned in the comments, this seems…
2 May 2017
Last week, during RailsConf 2017, Rails 5.1 shipped. If you followed the announcements, you’ve seen the big features: better integration with modern JavaScript, encrypted secrets, and system tests. And there’s my personal favorite: finally getting rid of the weird combo of form_for and form_tag, and replacing it with form_with. I can’t wait to try it. But the reason I love…
1 Mar 2017
What code of yours isn’t tested? Is it code that deals with complicated situations that you don’t control? Threads, running commands, git, networking, or UI? Our apps are most interesting when they’re complicated. They’re also most dangerous. And that’s why code that’s hard to test is exactly the kind of code that needs to be tested well. That doesn’t always…
14 Feb 2017
Have you ever wanted to import a bunch of data into your app from a CSV file? Or maybe you need to fix badly encoded characters in some of your customer reviews. Or you changed your mind about how you wanted to store data in Redis, and had to move everything from the old format to the new one. At…
22 Sept 2015
In last week’s article, you learned a short process that solves most encoding problems. But there’s one encoding problem that’s much harder to solve. I know you’ve seen it. (Or maybe you’ve seen it?) It’s when a curly quote turns into ’, or an em-dash turns into —. It’ll make you think you’ve gone crazy. It should just work! You…
16 Sept 2015
You only really think about a string’s encoding when it breaks. When you check your exception tracker and see Encoding::InvalidByteSequenceError: "\xFE" on UTF-8 staring you in the face. Or maybe “they’re” starts showing up as “they’re”. So, when you have a bad encoding, how do you figure out what broke? And how can you fix it? What is an encoding?…
8 Sept 2015
When you run into a strange, seemingly unsolvable bug, improving your logging can be the best step you can take. Great logging is the easiest way to detect and fix entire classes of bugs. When you log enough information, you can see how your data changes during a request. You can track the calls you make to other services, and…
1 Sept 2015
This article is also available in Korean, thanks to Soonsang Hong! Scopes are a great way to grab the right objects out of your database: app/models/review.rb class Review < ActiveRecord::Base scope :most_recent, -> (limit) { order("created_at desc").limit(limit) } end You’d use the scope like this: app/models/homepage_controller.rb @recent_reviews = Review.most_recent(5) Calling that scope, though, looks exactly like calling a class method…
29 Jul 2015
Why did Rails become so popular, so quickly? The simplicity helped, especially if you came from the Java, XML, Enterprise world. It was also marketed incredibly well. But that’s not everything. A lot of Rails’ success in the startup world came from a simple fact: The problems businesses have aren’t that unique. Rails was great at creating CRUD sites, while…
21 Jul 2015
Ruby conferences are awesome. There are so many people sharing so much knowledge, and you’ll take something away from almost every talk. And even if you can’t be there, new conferences mean lots of new talk videos. But there’s a problem. Videos take time. Even at 1.5x, they’ll still last 20 or 30 minutes each. And that’s focused time that’s…
15 Jul 2015
When you research how to deploy your Rails app, you’ll see a lot of names: Apache, Unicorn, Puma, Phusion Passenger, Nginx, Rainbows, and many more. They all seem to fit under the “deploying Rails” category of software, but there’s a key difference between them. Some are “web servers,” and others are “app servers.” Once you understand which is which, and…
8 Jul 2015
This article is also available in Korean, thanks to Dohyung Ahn! Thom Parkin made a great point in the comments of an earlier article of mine: Great advice. But you missed one very important [final] point. Since this is Open Source, once you have figured out the details of that feature/function where the documentation is a bit light, YOU SHOULD…
30 Jun 2015
Imagine a question that can be either “pending”, “approved”, or “flagged”. Or a phone number that’s a “home”, “office”, “mobile”, or “fax” (if it’s 1982). Some models call for this kind of data. An attribute that can have only one of a few different values. And that set of values almost never changes. It’s a situation where, if it were…
23 Jun 2015
This article is also available in Korean, thanks to Soonsang Hong! Rails’ scopes make it easy to find the records you want: app/models/review.rb class Review < ActiveRecord::Base belongs_to :restaurant scope :positive, -> { where("rating > 3.0") } end irb(main):001:0> Restaurant.first.reviews.positive.count Restaurant Load (0.4ms) SELECT `restaurants`.* FROM `restaurants` ORDER BY `restaurants`.`id` ASC LIMIT 1 (0.6ms) SELECT COUNT(*) FROM `reviews` WHERE `reviews`.`restaurant_id`…
16 Jun 2015
There are a ton of books, videos, podcasts, and courses for learning Rails. There’s no way you’d have time to go through them all! So what’s the best way for an absolute beginner to learn Ruby and Rails? Which resources should you start with, and when? Books and websites If you’re totally new to programming, the best place to start…
9 Jun 2015
You’re confident about the core ideas behind Rails. You can write working code, no problem. And you’re learning more about code quality, refactoring, writing great tests, and object-oriented design. By this point, you’re starting to feel like you’re getting it, that you’re on the path to becoming an expert. When you look backwards, you see just how far you’ve come,…
1 Jun 2015
When you use Ruby to wrap an API, you have to have a way to configure it. Maybe the wrapper needs a username and secret key, or maybe just a host. There are a few different ways to handle this. So which one should you choose? The easy, global way You might want your service to act like it’s always…