How to Access Variables Outside Scopes in Ruby In C# and Java, variables from the outer scope are visible to the inner scope. In Ruby, scopes are sharply separated, and nested visibility is
Ruby is a Meritocracy I recently read Russ Olsen's book Design Patterns in Ruby. In it, the author makes a wonderful distinction between statically vs. dynamically typed languages, which is different from all other comparisons I've seen.
How to Benchmark Rails Views This post explores the Benchmarkable module provided by Active Support to measure the execution time for rendering Rails views.
How to Benchmark Ruby Code The Benchmark module in the Ruby standard library helps you measure and report the time used to execute your code. This post explores three useful
Understanding Authenticity Tokens in Rails This post explores CSRF vulnerability and how Rails mitigates it using authenticity tokens. We will will learn why they're needed, how they're generated, how Rails uses them to verify the requests, and how to disable them for specific requests.
Metaprogramming in Ruby Metaprogramming in Ruby enables you to produce elegant, clean, and beautiful programs as well as unreadable, complex code that’s not maintainable. This book teaches you the powerful metaprogramming concepts in Ruby, and how to use them judiciously.
How to Get an Object's Class Name in Rails This post explores a few different ways in which you can get an object's class name in both Ruby and Rails.
A Deep Dive Into Database Migrations in Rails Like source code, database schema changes and evolves over time. Migrations are a feature of Active Record that allows you to manage the database schema
Attributes API in Rails Sometimes, you want to set default values on your ActiveRecord objects and convert them to a different type. Rails provides a handy attribute method that
How to Get the Current Absolute URL in Rails Every Rails controller includes two accessor methods pointing to the request and the response objects associated with the current HTTP request cycle. The request method
How to Rename a Database Column in Rails Solution 1: Undo Last Migration If it is a simple typo in the last migration, use the db:rollback command to undo the last change.
Metal Controller in Rails The ActionController::Base class is the great-grandfather of all Rails controllers, but doesn't get much attention. In this post, we will examine this Metal class and how it works. We'll also trace the path of an incoming HTTP request to Rails controllers.