Rails 3 screencasts

Great screencasts of upcoming Rails 3 release, that show you the main differences from Rails 2. Watch them here.

June 27, 2010 at 11:12 pm 2 comments

Two monitors on Windows

I am working with two monitors and there are 2 things that I use, one is now a standard Windows 7 feature and second is a patch to Flash that you might find useful:

1 – Moving applications / windows from one monitor to another – Now Windows 7 has a shortcut Shift-Win-Left and Shift-Win-Right that will move selected application from one monitor to another. Before I had to use an external app to do this. Very useful!

2 – I am often using my 2nd monitor to watch flash-based video. The annoying thing about it is that Flash won’t keep on full screen, as it react to a click outside of the screen and closes the full screen. Well, there is a patch to Flash, that allows you to watch full screen Flash on the second monitor, while working / browsing on the second. It works for Google Chrome as well! Go download it here.

June 24, 2010 at 11:18 am Leave a comment

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):

Q: Why can’t I simply download the latest MRI binary distributions for Windows from ruby-lang.org?

A: The binary packages for Windows found on ruby-lang.org lack several key components, such as OpenSSL, Zlib and Readline, which results in a broken experience for users trying install these binary distributions out-of-the-box. To compound the issue, other extensions are built-in, but lack essential bindings such as Tk and gdbm. Locating and installing the correct versions of these missing components can be tricky; RubyInstaller seeks to alleviate these difficulties and make the installation process dead-simple by providing everything you need to get started in one straightforward installation package.

Q: If I install both versions, is there some graceful way of selecting which version is active at a given time (e.g., which ruby.exe is invoked, which irb.bat is called, etc.)?

A: Pik is excellent for this coordination—check it out

===============

I haven’t yet installed it myself, but will definitely try it out. If you already have experience with the RubyInstaller – drop me a comment!

December 26, 2009 at 10:42 am Leave a comment

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:

<%# some ror code here %>
<%#= or some talking ror code here %>

December 14, 2009 at 3:33 pm Leave a comment

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.

1. Buggy cursor. Try it for yourself – type a very long line of code and try to move cursor – chances are it will get screwed up at some point in time – the cursor will jump, etc. The problems is with a module called readline. It’s a part of Ruby and was not updated from 2005, and nobody bothered to fix it for Windows. So, the only option is simply to disable it in your irb.bat file by adding the –noreadline switch like that:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"C:\Ruby\bin\ruby.exe" "C:\Ruby\bin\irb" --noreadline %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
"%~d0%~p0ruby.exe" "%~d0%~p0%~n0" --noreadline %*

Now, you won’t be able to use auto complete features of your console (tab), but the cursor works and the auto complete was not that useful for me.

While there, create a shortcut file called rc.bat in the ruby/bin directory, and insert there:

ruby script/console

2. Install HIRB and Wirble. HIRB is a nifty gem returns ActiveRecord objects in an SQL like table, which makes it much more readable:

irb>> Tag.last
  +-----+-------------------------+-------------+---------------+-----------+-----------+-------+
  | id  | created_at              | description | name          | namespace | predicate | value |
  +-----+-------------------------+-------------+---------------+-----------+-----------+-------+
  | 907 | 2009-03-06 21:10:41 UTC |             | gem:tags=yaml | gem       | tags      | yaml  |
  +-----+-------------------------+-------------+---------------+-----------+-----------+-------+
  1 row in set

To install hirb run: gem install hirb

Wirble does some colorizing stuff, although I have to say the default color scheme looks awful. To install wirble run: gem install wirble

You will also need to install win32console to get ANSI color support: gem install win32console

3. Now, automatically add HIRB (tabular query results), Wirble (color) and showing resulting SQL queries to the console.

In C:\Users\[your user name] create a file called “.irbrc” and paste these instructions there:

#
# allaboutruby.wordpress.com script/console configuration
# v 1.0, 2009 Nov

  require 'rubygems'

# load hirb
  require 'hirb'
  extend Hirb::Console
  Hirb::View.enable

# load Win32Console
  require 'Win32/Console/ANSI'

# start wirble (with color)
  require 'wirble'
  Wirble.init
  Wirble.colorize

# show SQL statements on in console mode
  if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
    require 'logger'
    RAILS_DEFAULT_LOGGER = Logger.new($stdout)
  end

So, now you have a modified console that works much better than the out of the box solution.

December 10, 2009 at 1:03 am 4 comments

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:

group_by  = "#{Vote.table_name}.voteable_id, #{column_names_for_tally}"

That’s it. Should work now.

December 6, 2009 at 3:19 pm Leave a comment

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.

By the way, to see how powerful Nokogiri is for parsing HTML, watch the episode on screenscraping by Ryan Bates.

December 5, 2009 at 7:35 pm Leave a comment

Older Posts


Recent posts

Starting to learn Rails?

Kindle

Get Kindle - the best e-book reader, that I personally use, and the only one that you can read on the beach - very useful: Kindle Wireless Reading Device (6" Display, Global Wireless, Latest Generation)

Follow

Get every new post delivered to your Inbox.

Join 30 other followers