If your site works with Google Analytics to gather data about user visits to your site, there can be situations where you would need to provide some information yourself. Let’s say, for example, that you want to track everyone time a user sees an ad you have on your ‘/our_ad’ page. If, however, you also show that ad when someone visits a different page, you would not have correct data about the ad views just by looking at page views for ‘/our_ad’. However, you can tell GA to count a view of the add everyone time someone see from the…
It seems like a common set up: when someone visits your website, you want to know what browser they are using. There are lots of reasons that you might want that information, from serving special components/styling, to gathering data on your users, to knowing if the browser supports a given feature. In general, there are three main ways to find out what browser someone is using, and one of them is highly frowned upon.
Browser Sniffing with User Agent
Web scraping is almost as easy as it is fun! All of the work is already done for us, all we have to do is harvest it. Nokogiri makes it even easier. For this blog, we’ll write a little app that shows the first headline that is displayed that day on the front of the Washington Post website. If you already know how to set up a basic app in Rails, just read section one about the web scraper. That section, however, will assume that you have a basic app as described in section two.
Creating the web scraper:
Grabbing data from and API in Rails is not overly complex. Doing it correctly, and with a little security, is a tougher task. Let’s first take a look at how to get it running quickly, a ‘proof on concept’ for bringing in the data, then let’s look at some things to consider to make improvements.
The basic steps for an API call are:
I had my Rails 5 app ready to go! It looked great on localhost:3000, beautiful background, good content, links working. Awesome, I’ve done 90% of the work! Now… all I have to do is get everything compiled for production. Ah… the OTHER 90% of the work.
Getting the asset pipeline to play nicely in deploy (in this case with Heroku) seems like it should be so basic as to either a) be really simple or b) be really well explained in the docs/stackoverflow. …
You’ve got an app with realtime updates! You built it on Rails. (Yay! You’re on Rails!) You used ActionCable! You run it locally and it’s working great. Ready to go. You ship to production, login and… crash. What’s going on?
The first thing to do is look at our logs. Heroku will provide you a behind the scenes look at what is going on with the
heroku logs command. For debugging, it is also convenient to add the
--tail command. …
There are various ways to add users to your Rails app and have them log in and out securely. For example, there are gems like Devise. There are also lots of tutorials online of how to set up authentication, like this one. But, most tutorials assume that you need to start from
What if you:
a) already have an app ready to go,
b) you’ve already seen authentication a time or two before and you just need a refresher, and
c) you don’t need the most cutting edge tech to protect your blog/recipe/todo/etc. app.
Well, you’ve come to…
They say that variety is the spice of life. No reason to think this would not hold true for learning programming, right?
I’m learning backend web development, focusing on Ruby on Rails. Recently, I spent a month working on a data analytics program. I got to look at lots of code, see my tests fail over and over, look at more code and, eventually, hopefully, maybe… see a test pass.
For an entire month, nothing but Atom and my terminal in dark mode. Even though I’m continuing with backend, every once in a while, it has been fruitful to take…
== looks at the characteristics of two objects and decides if those characteristics match. Therefore, just as
1 == 1 will return true,
 ==  will also return true. All objects in Ruby have an object identification number. These above comparisons will return true regardless of object id…
When I first learned to drive a stick-shift car, I didn’t know that there was a “friction point” or that the clutch and the gas had to be “mixed” carefully to shift into a new gear. I thought you simply pressed the clutch, moved the stick-thingy, let the clutch out, and punched the gas like Paul Walker.
A conceptual error, which may seem obvious, completely befuddled me and stifled my progress. The same thing happened with object instantiation in a recent project that I completed. With multiple classes, a multitude of different files, and a slew of tests, the offending…