RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  

wjgilmore — 16 posts

There are plenty of reasons users will want to sort and reorder lists, but implementing such a feature when using the has_many :through association isn't so obvious. In this post I'll show you how this is possible using the ActsAsList gem, and along the way show you how to load seed data, create a has_many :through relation, and use the great table_print gem. Read the post.
Location-based web applications calculate distance between objects using the latitudinal and longitudinal coordinates and the Haversine formula. But how does one determine an object's coordinates given a street address or IP address, let alone calculate the distance between two sets of coordinates? Fortunately the Geocoder gem turns these otherwise complex tasks into a fairly trivial matter. In this post I'll show you to to integrate Geocoder into your Rails application.
Taking a tag-based approach to content categorization gives your users much more flexibility in terms of quickly finding desired information, products, and blog entries. In this article I'll show you how to incorporate tagging and tag clouds into your Rails application using the powerful Acts As Taggable On gem. Read the article
The decent_exposure gem can go a long way towards cleaning up your RESTful Rails controllers, resulting in significantly less boilerplate code you'll have to write to implement conventional RESTful actions. This tutorial introduces you to this great gem, and offer several examples demonstrating just how much code decent_exposure can eliminate.
The fantastic Devise authentication gem asks registering users for just two items: an e-mail address and password. Chances are you'll want to subsequently gather additional details, such as the user's name or location, typically done through an account profile management form. In this post I show you how this is accomplished.
A fundamental Active Record feature known as eager loading regularly trips up new Rails developers to the detriment of their application's performance. In this post I offer a concrete example illustrating the difference between the includes and joins approaches, complete with a log of the queries executed when each approach is implemented.
Rails bundles default 404 (file not found), 422 (unprocessable entity), and 500 (internal server error) pages into every newly generated application. While they get the job done, these pages are pretty bland, so in this post I’ll show you how to update them to suit the logic and design requirements of your application.
I use the Rails console repeatedly throughout the day, but peering into object data can be a bit difficult due to poor formatting. Fortunately, a great gem called Awesome Print can bring an end to the formatting blues. In this blog post I introduce Awesome Print, and show you how to integrate it into your Rails console.
I'm very pleased to announce the release of a book I've been working on for some time now, "Easy Active Record for Rails Developers". The book covers everything under the sun pertaining to Active Record, including model and schema management, validations, queries, data management, extensive coverage of associations, nested forms, model testing using RSpec and FactoryGirl, and much, much more. Readers learn through walkthroughs of many examples based around a real-world project called ArcadeNomad that tracks the location of retro 1980's arcade games.
It is often useful to know how many records are associated with a model identified as being the parent in a belongs_to relationship. Active Record's default behavior is to determine this number using a COUNT(*) query. Fortunately, you can avoid this additional costly query by caching the associated record account with a few simple modifications to your Rails application. Read the tutorial.
Changing the Rails Console Prompt
The Rails Console is an indispensable tool, providing developers with an easy way to experiment with models, Ruby syntax, and pretty much any other code associated with a Rails project. But the default prompt is a bit overbearing, including by default the Ruby version and number of commands executed in the current session. You can easily simplify the default prompt by following the instructions found in this easy tip.
When working with Ruby and Rails, a common source of confusion involves mixing up nil?, blank?, and empty?. All three methods clearly deal with determining whether a data structure is assigned a value, but there are different degrees of nothingness, and in the world of programming those degrees are important. This blog post helps to dispel the confusion by working through a number of different examples.
Paginating database results is a standard feature of most web applications, yet isn’t something you’d want to necessarily implement on your own. Fortunately, Rails developers have a whole host of options at their disposal, including the will_paginate gem. This post shows you how to easily integrate will_paginate into your Rails application. Read the post.
The attr_accessible macro has long been a Rails mainstay, playing a major role in preventing malicious access of sensitive model attributes. However it (and its sibling attr_protected) was deprecated in Rails 4 in preference of a new approach known as "strong parameters". In the latest Easy Active Record blog entry I introduce strong parameters, explaining why attr_accessible was inconvenient and demonstrating the advantages gained by the new strong parameters approach.
Many applications require the retrieval of random database records (for instance to highlight a random product in an online store). There are several ways to accomplish this task, but efficiency varies widely and becomes more pronounced as your database grows in size. This blog post demonstrates two common approaches when using Rails Active Record and MySQL, and benchmarks both (using the Ruby Benchmark module) to demonstrate their efficiency.
In the runup to the publication of my new book, "Easy Active Record for Rails Developers", I'm publishing a series of posts covering commonly confusing or little-used Active Record features. The latest discusses two approaches to creating default Active Record model attribute values.