I ran into this doozy today:
In math, a+b always equals b+a. Not always the case with Ruby and Time objects.
addthis_url = ‘http%3A%2F%2Fwww.alandelevie.com%2F2010%2F07%2F19%2Fthe-perils-of-syntactic-sugar-in-ruby%2F’;
addthis_title = ‘The+perils+of+syntactic+sugar+in+Ruby’;
addthis_pub = ”;
For when you don’t want to type a dozen times, add this to application_helper.rb:
def nbsp(n=1)
n.times.map {” ”}
end
In a view:
<%= nbsp 5 %>
replaces
addthis_url = ‘http%3A%2F%2Fwww.alandelevie.com%2F2010%2F07%2F16%2Ftrivial-rails-tip-easy-html-spaces%2F’;
addthis_title = ‘Trivial+Rails+tip%3A+easy+html+spaces’;
addthis_pub = ”;
Up until now, I’ve done nearly all of my Rails programming on Windows Vista (64 bit). The environment has been pretty good, but it’s time for a change. This was probably due a while ago, but I’ve decided to explore Linux with a dual boot of Ubuntu 10.x.
Thanks to StackOverflow and some Googling, I got [...]
I recently asked a question on Stackoverflow about when it’s best to use a case statement versus using a Hash in Ruby. I got a few answers including a really good specific answer. But another more general answer really struck me, so I’m sharing it here.
Igor Krivokon wrote:
In general, “better” in programming means different things. [...]
I’ve been working on an admin panel for a certain Rails app. One of the most common tasks to writing an admin panel is to generate a table where each column is a different attribute for your model. This is easy to do, but very tedious.
To simplify the task, I looked at metaprogramming. Metaprogramming with [...]
Eager loading in ActiveRecord is a great feature. It prevents what’s called the “n+1″ problem. From the docs (emphasis mine):
Eager loading is a way to find objects of a certain class and a number of named associations. This is one of the easiest ways of to prevent the dreaded 1+N problem in which fetching 100 [...]