Feed items

RubyInstaller RC1 is out

There’s finally an easy way to install Rails with Ruby 1.9 using the recently released RubyInstaller (Release Candidate). RubyInstaller uses MinGW (Windows port of GCC compiler) to create binaries and provides better compatibility with the Windows environment. You can get more info and download it here.

This marks the end of Ruby’s OneClickInstaller that majority of people used to install Ruby.

Main things to note (from the official FAQ):

Commenting out chunks of view

It’s not as easy to comment out big chunks of Rails erb (view) code. Here’s the one that seems to work fine for people:

<% if false %><!-- comment start -->
...
<% ... some code ... %>
some html
<% ... more code ... %>
<!-- comment end --><% end %>

If you simply try using HTML comments, the code will still execute.

Finally, if you want to simply comment out a single ERB statement, put # just after <%, like this:

Upgrading the script/console in Windows VISTA environment

If you haven’t been actively using script/console – you should start it now. It allows you to test things out in the environment of your project with a direct feedback. So, if you want to check those quirky database queries or how a new plugin works, run the script/console and start coding.

However, as seemingly everything in Ruby Rails, the console is a bit buggy in Windows. This calls for a console upgrade. At the same time we will include some further improvements as well to make your console the best firend.

vote_fu to work in Heroku (Postgres)

In order to make vote_fu work in Heroku’s PostgreSQL you need to make a slight modification in the tally method, to follow a classical SQL notation:

Add this method in acts_as_voteable.rb just after options_for_tally method:

	def column_names_for_tally
	   column_names.map { |column| "#{table_name}.#{column}" }.join(", ")
	end

In options_for_tally method find line that starts with “group_by =” and replace it with:

Rails 2.3.5

Rails 2.3.5 is out. It provides a better Ruby 1.9 compatibility, you will now not need to escape everything with h() if you install a RailsXss plugin – I think this is great, and now the Nokogiri XML parser can be used.

Hosting your Rails app – first look at Heroku

Introduction: You should really get professional help

I am building an app and needed to show an unfinished version to some guy. As I am building on a local (windows!) box, I decided that it’s time to invest some time in finding out what options there are to host a Rails app.

Rails caching – resources

When you create anything serious on Ruby on Rails, you will most definitely need to start thinking about caching. As Ruby is a high-level language, a lot of crunching goes on to make the magic work. So in order for all this magic to work you should ensure that the heavy-lifting is done only once and after that you just use the results.

Good news is that caching in RoR is very powerful standard feature.

Ruby variables

Something that you might have to watch out for when working with Ruby is how it works with variables. Ruby variables are only references (pointers) to objects. Therefore, you might experience a subtle behavior that you probably don’t expect. Try this out in your irb:

Timing attack? What’s that about?

If you are wondering, like me, what was the “timing attack” fix update in the latest 2.3.4 for, you can read this post here. Basically, if a comparison is made between two strings, it’s done one character at a time, and it stops when the first differing character is encountered. Therefore a potential hacker could measure how much time it takes to check a cookie hash to see if it’s correct or not.

Defining methods in Ruby

1 – Hashes in method calls

You must have seen this syntax in Rails a lot, for example when using this Paperclip plugin, you would put this in your model: