Tag: Rails

Expose HTTP Headers in CORS

For APIs, it seems more and more data is making its way into the HTTP headers. Recently, whilst adding a Link header, for paging data, into the HTTP response, I realized that my browser code couldn’t see it. Who was the culprit? CORS, of course.

Permit Array in Rails Strong Parameters

Rails 4 introduced the pattern of strong parameters at the controller layer. As a best practice, you will explicitly list the parameters that an endpoint should accept in payloads. Arrays are specified just slightly different.

Debug Ruby and Rails

Interactive debugging can sometimes be faster and more effective in helping you code than a puts statement. It’s easy to get interactive debugging in Ruby or on Rails with the help of a nice gem.

Import Erb Into Karma

Rails asset pipeline allows you to use erb helpers in your CoffeeScript. You’ll still need to bring get these files into Karma runner. It’s really easy. You just need to get to know your Karma config options.

Setup Slim on Sinatra

Sintra is a light web server that’s easy to start writing Ruby on. Coming from Node/Express, I feel quite at home there. Slim also feels like another JavaScript-world templating language, Jade, that I’ve had good experiences with. Slim makes for quick templating and feels quite nice compared to ERB if you can handle the Haml style. It’s likewise quick and easy to get working on Sinatra.

Slim templates

Multiple Yields in an ERB Template

When you setup a new Rails project, you’ll have a single layout file which has a single default yield block. This will soon be inadequate, and you’ll want another. Here’s how to setup multiple yield blocks per ERB template.

Older