When dealing with time zones in Rails, there is one key fact to keep in mind: Rails has configurable time...

github.com

Stackprof is a sampling call-stack profile for Ruby 2.1+. Instead of tracking all method calls, it will simply collect...

Our preferred way of testing ActiveRecord is to simply create/update/destroy the record and then check if the expected behavior has...

Validations should be covered by a model's spec. This card shows how to test an individual validation. This is...

makandra dev

Geordi is now (partially) tested with Cucumber. Yay! geordi cucumber supports a new @solo tag. Scenarios tagged with @solo...

github.com

Using Scenic, you can bring the power of SQL views to your Rails application without having to switch your schema...

When dealing with AR scopes, you can remove conditions, order, etc by using the unscope method. It is available on...

Rails 4 introduced raising an error on pending migrations. This is most annoying when you are crafting a migration but...

Some tasks in a web application are better not done live when a user request a page, but in the...

github.com

Rails 5 will introduce ActiveRecord::Relation#or. On Rails 4 and 3.2 you can use the activerecord_any_of gem...

For each movie in MovieDB, we want to track which other movie it was inspired by. For...

It smells. Rethink your code design. Code example with makandra/has_defaults: class Post < ActiveRecord::Base has_defaults tags: [] # field in db...

makandra Curriculum

Built-in matchers Get an overview of all the matchers that are built into RSpec. Play with some of...

makandra Curriculum

Read the Rails Guide about Active Record migrations Understand why we never use models in migrations. Checkout the repository...

As you most likely know validates_uniqness_of :foreign_id does not allow nil values by default.

Use form models to handle this problem Or soften the validation to validates_presence_of :parent

Use base_class. This traverses up the hierarchy until it encounters either a class inheriting from ActiveRecord::Base or

Rubymonk training Read the following Rubymonk articles: Ruby Primer: Ascent (archived copy) Metaprogramming Ruby (archived copy) Metaprogramming Ruby: Ascent (archived...

In tests, it is sometimes useful to create records with specific ids. On PostgreSQL this can cause problems: Usually, PostgreSQL...

makandra Curriculum

Read (or re-read) the following chapters from our book Growing Rails Applications in Practice (it’s in our...

The migration DSL now supports adding and removing foreign keys. They are dumped to schema.rb as well. At this time...

Learn to treat files as an ActiveRecord attribute type, like :string or :integer Research Look at the README for...

In this card we will learn to write code that scales with a large number of database records. We will...

Rails is our web framework. Goals Be able to write a simple Rails application. Understand how Rails talks to the...