Assets not loading on Elastic Beanstalk in Safari

I’ve been having an issue. I use Elastic Beanstalk for deploying most of my applications – it’s a layer over the top of Amazon’s EC2 service that handles a load of the complexity for you. I simply define which platform I want (Ruby 2.3 with Puma), define any components that need to be installed on… Continue reading

How do I reference a font or an image from my CSS files?

Rails uses a thing called the “asset pipeline” to pre-process your assets (Javascript, CSS, images and fonts). This has a number of advantages – Javascript get minified and squashed into a single file for faster transmission, and the same happens to your CSS as well. All your static assets (the single JS file, the single… Continue reading

How does Rails work?

So you’ve decided to learn Rails. You could dive straight in to learning the code, but Rails is an opinionated framework and it expects certain things to be done a certain way. A high-level understanding of how it’s structured and what goes where is always important. So let’s follow a hypothetical web-request on its journey… Continue reading

Multiple models in a single form

Following on from our form containing diverse controls, let’s look at how to update multiple models from a single form. Rails has a concept of “nested” models, generally represented by has_many relationships. As we’ve been dealing with people, let’s give our person multiple addresses:

The first bit is simple enough, the second bit tells… Continue reading

How do I make a forms in Rails (part 2)?

After setting up a basic form, you probably need to fill it with some controls. Until the advent of HTML 5 (which I can’t rely on because many of my clients are still stuck with old browsers), there wasn’t really much choice with these controls. Rails offers helpers for generating these controls, and fills some… Continue reading

How do I prevent an AJAX link from being clicked twice?

I have a link that I want users to click when they “like” a POST. It’s implemented using AJAX and looks like this:

First thing to note – I never use the Rails remote helpers. They are nice and easy to get started but you lose a lot of control. And if you use… Continue reading

Why shouldn’t I pass instance variables to views?

One of the design decisions in Rails that I thoroughly disagree with is the fact that instance variables are magically passed from the controller to the views. For example, take this example from yesterday:

This uses a load of Rails magic. It renders app/views/documents/index.html.erb for you and sends @documents to it; presumably in index.html.erb… Continue reading