4 Lessons Learned Doing Angular on Rails

We’ve been working on one of our first Angular projects with a Rails backend. It’s been a great experience. I wanted to share a few things we learned that we hope are helpful to others building Angular on Rails apps.

Rails 4 Countdown to 2013 | The Remarkable Labs Blog

With the impending release of Ruby on Rails 4, it looks like a lot of developers will be updating their web applications in the coming new year.

To help with this transition, over the next 31 days, we are going to be releasing a series of blog posts going over everything you will need to know about Rails 4 for an effortless upgrade.

How to express ordinality with numbers in Rails

If you have an integer and want to use it to represent an element's position (like "1st" for 1, or "2nd" for 2), you can use ActiveSupport's ordinalize:

1.ordinalize     # => "1st"
2.ordinalize     # => "2nd"
1002.ordinalize  # => "1002nd"
1003.ordinalize  # => "1003rd"
-11.ordinalize   # => "-11th"
-1001.ordinalize # => "-1001st"

When Rails no longer renders changes in view templates or Sass stylesheets

Do you have page caching enabled for the development environment and there are cached pages lying around in public/?

Error during Rails 5 upgrade: Environment data not found in the schema

This error is raised because your old database does not have a configured environment yet, which Rails 5 enforces.

If this error occurs while migrating your parallel test databases, make sure to update the parallel_tests gem first: current versions fix this. If you're still using Cucumber < v3, the latest version of parallel_tests will be 2.18.0.

Migrations are versioned in Rails 5 | BigBinary Blog

Rails 5 migration classes look like this now:

class CreateUsers < ActiveRecord::Migration[5.0]

Mind the [5.0] at the end.

They do this to evolve the ActiveRecord::Migration API without breaking your historical migrations in db/migrate.

Using PostgreSQL and jsonb with Ruby on Rails

Postgres 9.4 introduces a new column type: jsonb. json and jsonb columns store data differently, so just compare the two when you want to store JSON data and choose the one that matches your use case best.

Rails 4.2 includes support for jsonb columns, too. The article outlines different ways on how to interact with the serialized object.

Rails 4 drops support for the :assets group in Gemfile

Previously the assets group existed to avoid unintended compilation-on-demand in production. As Rails 4 doesn't behave like that anymore, it made sense to remove the asset group.

How to remove/disable the automatic XSS protection helper html escaping for Rails 3

How to remove/disable the automatic XSS protection helper html escaping for Rails 3.

This is probably a horrible idea.

Extracting the conditions of a named scope in Rails 2.3

See attached link for a way to extract the conditions of a named scope in Rails 2.3.

Get Your App Ready for Rails 4

Let’s take a look at what you need to do to get your app ready for Rails 4.

Asset pipeline for Rails 2

The asset pipeline from Rails 3.1 packported to 2.3. By Michael Grosser from parallel_tests fame.

Using ENUMs with Rails - See John Code

This sounds promising:

The best part from the Rails side, is that you don’t have to change anything at all in your code to swap a varchar out for an ENUM.

Three quick Rails console tips

How to call routes, make requests and try out helpers from the Rails console.

Locale: Localisation for Rails developers

A possible way for localisation in Rails applications that allows editing translations remotely.

Configuration for Rails, the Right Way

I still see people promoting various gems and plugins to handle miscellaneous configuration elements for your application. One little known secret is that Rails 3 allows you to define your own configuration elements trivially.

Making the rails 3.1. asset pipeline and asset precompiling work in production mode

Recently, we had an interesting lunch-break with the rails 3.1. asset-pipeline in production mode. Daniel Zahn made a blogpost about our journey, precompiling assets, fingerprinting, Haml, Sass & Compass and what he calls "the dark heinous hutch".

Why developers should be force-fed state machines

Most web applications contain several examples of state machines, including accounts and subscriptions, invoices, orders, blog posts, and many more. The problem is that you might not necessarily think of them as state machines while designing your application. Therefore, it is good to have some indicators to recognize them early on. The easiest way is to look at your data model.

Matching elements on complex web pages with Webrat

XPath matchers can be combined with CSS-selector matchers. This is really useful if not, for example, the content of an element should be matched but the element itself like in the following example. Here a form is used to display data as default value in its input elements. This can be the case in web applications in which data should be edited easily without additional clicks.

Rails: Disabling logging entirely

In an environment:

config.logger = Logger.new('/dev/null')

JSONP for Rails

The rack-contrib gem brings a JSONP middleware that just works™. Whenever a JSON request has a callback parameter, it will wrap the application's JSON response appropriately.

The project is a bit dated, but the JSONP middleware is ok.

rack-mini-profiler - the Secret Weapon of Ruby and Rails Speed

rack-mini-profiler is a powerful Swiss army knife for Rack app performance. Measure SQL queries, memory allocation and CPU time.

This should probably not be loaded in production (the article recommends otherwise), but this looks like a useful tool.

6 front-end techniques for Rails developers. Part I: From big ball of mud to separated concerns

Amazing guide how to divide a ball of Javascript spaghetti distinct separate layers (model, view, controller, backend adapter).

It does not use a Javascript framework.

Mute Rails asset pipeline log messages

quiet_assets helps with disabling asset pipeline log messages in the development log. When the gem is added, asset pipeline logs are suppressed by default.

If you want to disable muting temporarily, add config.quiet_assets = false to your config/application.rb.