kyleke.es
I'm Kyle Keesling, an Indianapolis-based pixel pusher

Migrating Your Assets from Paperclip to ActiveStorage

With the release of Rails 5.2 there is now a native, built in way to handle asset uploads and management called ActiveStorage, making the need to use gems like Paperclip, Carrierwave, or Fog, with Paperclip going so far as writing a migration guide; implying that it may not be long for this world.

To be honest I didn’t even know that Paperclip had written a migration guide until I started writing this post, and while it’s fairly comprehensive, it doesn’t do what in my mind is one of the most important tasks - migrating the files on the remote host.

With that in mind I’ve used the following rake tasks with great success to move assets for many of my models.

There are two flavors here, migrating assets while changing their name, or just plain old moving.

Moving an Asset While Changing Its Name

In my case I had a User class with a Paperclip attachment called headshot. I never really liked that we used the term headshot, so this was the perfect opportunity to change it to avatar.

This scenario is surprisingly easier due and the fact that we don’t have to worry about a naming collision (headshot to avatar), which means we can still use paperclip’s built in URL helpers in our rake task.

Just remember to leave your Paperclip declarations on your model until after you run your rake task.

Moving an Asset As-is

In reality, you’ll likely want to keep the same name, which requires us to get a little more crafty. In my case I have an Organization class with a logo. We wanted to keep using that term, but in order to do so, we have to remove the Paperclip declarations from the model, otherwise would couldn’t refer to all the new ActiveStorage goodness.

To get around this we just need to utilize the actual asset URL in our rake task.

This rake task is pretty straightforward, but what got a little sticky was dealing with filename extensions, mainly the fact that sometimes uploaded files don’t have them, so that’s what lines 5 & 6 are about.

A Few Considerations

There are a few tradeoffs that you’ll have to consider if you use this method though.

The first advantage that you get is that these tasks can be ran from any server, including your dev environment, even before you deploy any actual code.

In my case I ran the rake tasks on my laptop, and as soon as the updated code was deployed to the server, the assets were already there. The only thing left to do is to remove the old assets when you’re ready, but they are still there in the event you need to rollback your deploy.

The biggest downside to this method is simply the fact that you are duplicating all of your assets temporarily. In my app I was able to move thousands of image files in a matter of hours, but if you have millions of records, or very large assets, this method might not be your best option.

Bootstrap 3 Responsive Button Groups

Ever been disappointed/pissed off with how Bootstrap handles (read ignores) button formatting on smaller screens? Check this out:

Makes this:

Look like this:

Aaron Draplin Takes On a Logo Design Challenge

I come across this video yesterday of Aaron Draplin, of Field Notes and DDC fame, talking about his approach to logo/corporate identity design. I’m a big fan of his style in general but he makes some really good points regarding how to approach these types of projects.

Submarine Sandwich

This video is just flat out weird, but I can’t stop watching it.

Rails Testing

Below is a series of tweets that I should’ve composed a quick post out of rather than rapid-firing it out over twitter. Maybe I’ll come up with some more to say about this here before long.

When Using CurrentC, You're the Product

I’ve only used  Pay a few times over the past two weeks, but I already find myself checking for it at every store I step foot into. It’s more convenient than getting into my wallet and swiping a card… and it’s just plain cool.

While the coolness factor will wear off over time, knowing the security measures being taken to ensure my financial/personal details are kept private is a huge win, even more so than the impending EMV roll-out (finally) happening here in the US over the next few years.

All that said, this week’s push-back really had me scratching my head at first. We first heard about Rite-Aid pulling all NFC-based payments from their stores, and CVS quickly follow suit, doing this in favor of a new service called CurrentC.

CurrentC is a new invite-only payment app created members of MCX, which is a group of merchants who are trying to “streamline the customer shopping experience across all major retail verticals.”1

Josh Constine’s article on TechCrunch does a great job describing the basics:

When it’s time for a user to check out, they request to pay with CurrentC. The consumer then unlocks their phone, opens the CurrentC app, opens the code scanner, and scans the QR code shown on the cashier’s screen. In some case, the reverse may happen where the consumer’s CurrentC app displays a payment code and the cashier scans it. If a QR code can’t be generated, a manually entered numeric code may be offered.

I can’t see how unlocking my phone, launching an app, and taking a picture of a QR code could even come close to the level of ease that  Pay, or any other NFC-based payment system, offers.

Rather than sending the customer’s financial data over the air, transactions trigger the transmission of a token placeholder. This is then securely converted by the financial institution to process the ACH payment and charge the user.

CurrentC notes it may share info with your device maker, app store, or developer tool makers. Oddly, it will collect health data. Precise location information is used to verify you’re at the retailer where you’re making a transaction, and if you opt in it can be used for marketing or advertising. CurrentC notes that you can opt in to be able to capture and store photos in the app for a hypothetical visual shopping list or other features down the road.

These quotes tell you all you need to know about MCX’s motives. This decision was made with the merchants’ best interests in mind, not the consumer, they get more personal data about their customers and cut out the transaction fees from the payment processors by using ACH payments. Many people, including myself2, actually prefer credit cards over debit cards/bank transfers. Points, cash-back, and travel credits are big business for banks, and can be beneficial to consumers too, so I don’t expect this to be ironed out any time too soon.

If you’re as interested in this as I am you may want to follow Nick Arnott’s coverage/commentary on iMore and twitter. He’s doing a great job of explaining the implications from both a consumer-facing and technological level.

  1. Read in @marcoarment’s ‘BRANNNNNDS’ voice 

  2. Costco AMEX FTW 

Fire Talk with Me

I recently started listening to a newer podcast on esn.fm called Fire Talk with Me. It’s a limited edition show that runs through each episode of David Lynch’s masterpiece Twin Peaks, and gives the perspectives of one person who experienced the show during its inital run, Jeremy Smith, and one who’s experiencing it for the first time, Allie Goertz. They have guests on along the way, but are very good about not spoiling anything for Allie. They have currently covered the pilot and the first four episodes, releasing a new one each week.

Whether you are a total Lynch fanatic, or know nothing about Twin Peaks, this is a great podcast to supplement your viewing experience, which can stream in its entirety on Netflix, or splurge for the Blu-Ray set, complete with the prequel movie, Fire Walk with Me.

Either way I can’t recommend you watch this enough. It gives you a lot of perspective as to what shaped some of the ideas/styles of some of today’s best television shows.

The Walking Dead: The Game - Season 2

The first season if this game was fantastic, and I highly recommend it, even if you aren’t particularly a fan of the TV show. These games are set in the same universe but follow an entirely seperate set of characters… with the occasional cameo :)

The Dirty Secret Behind the Salesforce $1M Hackathon

I know that if I put this much time and effort into something and the judges didn’t even launch my code, I’d be pretty upset, but anyone going into this thinking it was completely unbiased, and not a huge marketing ploy cooked up to benefit the host is just naive. On the other hand, it’s impossible to get the one true story in situations like these.

At any rate this is why I’m increasingly dismissive of any corporate “hackathon” competitions. They are rarely setup with the developers’ best interests in mind, but rather for some other type of self-serving agenda1.

  1. “I’m not lumping any type of charity/non-profit events in here, those clearly articulate who these projects benefit” 

Creating a Repeating Footer w/ Prawn

I’ve been using Prawn for the past 3 years to generate PDFs in my Rails projects. It has a little bit of a learning curve up front but gives you much more power than just rendering out your web views as PDFs.

That said one problem I ran across was how to design/implement repeating footer. After a lot of digging I came up with the solution below:

If you are curious how you actually go about using this PDF in your project, you can refer to Ryan Bates’ always awesome Railscasts, episode #153.

On a side note, Ryan took the summer off and was originally going to come back in September, but then later announced he wasn’t ready to come back yet. While I can definitely understand burnout and needing some time away, I hope to see him back in action soon.