May 15, 2015 by Daniel P. Clark

Speed Up Your Rails Views By Deferring Changes

Nobody likes a slow website.  And the more notifications and content privileges you calculate beforehand the longer your web requests take to load and send.  The most efficient way to change this is to make as much of your site static as you can and defer your changes to after the page has fully loaded. …

Continue Reading »

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 12, 2015 by Daniel P. Clark

Fake a SMTP Server with Python for Rails Testing

So I’ve been in the process of writing an integration test to verify the flow of registration through some unique conditions.  One thing I ran into while writing my Rails test was this error. Connection refused – connect(2) for nil port 25 After looking around at documentation on what to do for testing it seemed…

Continue Reading »

May 11, 2015 by Daniel P. Clark

HABTM; You Don’t Need It

My point: “For any valid use of implementing a has_and_belongs_to_many there is an equally valid way to implement it without it.” A few reasons: Rails had changed both the way it worked and removed it from reflections for a brief period (Rails version 4.1.0 and 4.1.1).  Also the preferred implementation is to use has_many :through. …

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 »

May 2, 2015 by Daniel P. Clark

Private Module Methods in Ruby

So this is something I’ve looked into many times over the years and have never found an answer to.  But great news is that I’ve found a way! It’s as simple as defining module methods as private within the singleton class.  Here’s how I did it in my gem PolyBelongsTo

My gem gets included…

Continue Reading »

April 30, 2015 by Daniel P. Clark

Have problems testing methods that query ActiveRecord?

Sometimes you’ll run into a problem that won’t reveal an answer.  I ran into a problem I had come across before in that past to which I knew I hadn’t really solved.  I have a custom method that looks up an ActiveRecord query and makes a change.  But both times I’ve tried to test the…

Continue Reading »

April 16, 2015 by Daniel P. Clark

Undefining a CSS attribute (and rant)

Stack Overflow Conduct One downside to Stack Overflow is the abuse of power the higher ranking users exercise when they misunderstand the question posed.  Many are too quick to jump the gun on voting out or down questions rather than simply asking for clarification before action is taken.  S.O. has guidelines for people to do…

Continue Reading »

April 8, 2015 by Daniel P. Clark

Documenting Your Code

I’ve been hearing a majority of developers saying things like “You’re code should be easy enough to understand that you don’t need to document it.” and “Comments are lies waiting to happen”.  I was okay with this and after hearing this for a while I eventually stopped writing code comments. I watched a conference talk…

Continue Reading »

April 8, 2015 by Daniel P. Clark

ActiveRecord vs Me… Round 1 – FIGHT!

I’ve done a fair bit of work in creating a library that integrates with ActiveRecord Objects.  I also have a pretty good grasp on mixins/inheritance.  Yet I still run into situations where trying include, extend, and techniques for monkey patching just don’t work out. I was trying to implement a method like first_or_create on the…

Continue Reading »

Page 4 of 11
1 2 3 4 5 6 11
1 2 3 4 5 6 11