May 13, 2015 by Daniel P. Clark

Rails: Don’t “pluck” Unnecessarily

Using pluck in Rails is both quick and efficient.  But there are cases where it’s not what you want to use.  For example if you’re selecting all users who have contacts, you might see something like this.

Rails’ where method allows for Arrays of items for lookup so the above code might turn into…

Continue Reading »

May 9, 2015 by Daniel P. Clark

Chaining an Array into Arel ors

I’d like to keep this post short.  So the basic idea behind this is that Arel helps you build SQL queries.  When you want to join multiple queries together into one result you use Arel’s or method.  The way Arel chains additional query commands is by nesting inside the current query.  For example, if you…

Continue Reading »

March 31, 2015 by Daniel P. Clark

Rails 4’s Awesome enums

In Rails 4 enum was introduced to support a feature that people were building by hand or by gem.  What enum does for you is it associates a symbol list for you to reference which will be stored in the database as an integer.  So :cow could be 0 and :dog could be 1 in…

Continue Reading »

February 10, 2015 by Daniel P. Clark

Rails Polymorphic Associations

What is a polymorphic association you might ask?  It’s where an ActiveRecord model can potentially belong to more than one other kind of model record.  So the single instance of your car belongs to you, a person, whereas other cars may individually belong to a car lot, a business. Why do we need it? In…

Continue Reading »

February 6, 2015 by Daniel P. Clark

Getting Into Rails Model Queries

For the longest time I was stubborn against learning “database programming”.  It was the abhorrent syntax that made me so resistant.  But low and behold there came Rails who found it in their heart to make a middle man ActiveRecord in which to slay the evil abhorrent syntax by resolving all good details in more…

Continue Reading »

January 16, 2015 by Daniel P. Clark

The 500 Millisecond Rails Partial

Click… 15 seconds later: “Something went wrong”.  So that happened.  I’d written a web based email client and it was taking too long to load.  If it reached 15 seconds it would quit because of the servers time-out setting.  Here’s my journey into finding out what went down. First things first, I needed to know…

Continue Reading »