All posts tagged rails

An introduction to SASS and HAML

From my talk on learning HAML and SASS for Magma Rails 2011.

Slides and an HTML reference version below. A sample application with all code examples is at https://github.com/jonathandean/SASS-and-HAML-FTW.

Continue reading →

delayed_job in Rails 3

I searched for how to use delayed_job and Rails 3 on Google last night and went down a little rabbit hole I thought I could try to help someone else avoid. I ended up at http://www.dixis.com/?p=335 which provided a great, but out of date, article on how to do this. It recommends using collectiveidea’s fork of delayed_job in the master branch, but as it turns out the latest in the master branch in is in flux at the moment. The ActiveRecord backend is currently being abstracted into it’s own gem (which is a great idea) but that means the generators to make the database tables are no longer there. It also in general seems not ready for prime time.

Continue reading →

Dividing numbers in Ruby returning zero or an integer unexpectedly?

There’s a “quirk” about Ruby that I often forget when going back to it after a long period of time using other languages. If you divide two integers in Ruby then it’s going to give you an integer as a result. Consider the following:

some_int = 3
another_int = 2
answer = some_int / another_int  # answer is going to be 1 here

To fix this you’ll need to convert your integers to floats first. The following will work:

some_int = 3
another_int = 2
answer = some_int.to_f / another_int.to_f  # answer is going to be 1.5 here

the to_f function is going to convert the integers to floats and give you the float (decimal) answer.