Railsblog

written by silvio on September 16th, 2010 @ 11:11 AM

As you may have noticed, it’s been a long time since my last post.

I’m moving most of my blogger efforts to Railsblog, a blog written in italian mainly focused on Ruby on Rails.

You can keep following me on http://www.railsblog.it

A good Rails 3 article from IBM

written by silvio on March 27th, 2010 @ 08:03 PM

That’s another very good article covering Rails 3, from IBM developerWorks, the IBM’s resource for developers and IT professionals.

In this article, you’ll take a look at Rails 3 and its many changes and additions and create a new Rails 3 application from scratch.

How to upgrade Rails 2 apps to Rails 3 free screencast

written by silvio on February 2nd, 2010 @ 11:44 AM

A fantastic screencast from Geoffrey Grosenbach showing how to convert an app from Rails 2 to Rails 3 edge!

Get it there

From his article :

“For several months people have wondered, ‘Where can I download a video that features a developer stumbling through an upgrade of a Rails 2 app to Rails 3?’

I’m proud to say that an answer is now available!

In only 25 minutes, I convert my news screenshot site from Rails 2.x to Rails 3 (prerelease, from source).

It features the newest bundler (0.9.0.pre), Jeremy McAnally’s rails-upgrade script, new routes, Arel-based ActiveRecord queries, and more.”

SOURCE

Exploring Rails 3 free online conference

written by silvio on January 30th, 2010 @ 12:19 PM

Thursday, February 18th joint this fantastic online conference.

Rails 3 is taking its final shape, so there’s no better time to take a close look at the work that’s been done in the past year.
Join us for a series of talks on everything you’ll need to get started with it – from creating a new application, to upgrading from Rails 2, to the foundation that makes it all possible.

Who’s Speaking?

Getting up-to-date with Rails 3
Speaker: Yehuda Katz, Engine Yard
Rails 3 is a lot of things. Yehuda will go through the important high-level changes, giving you a starting point for digging into the improvements the Rails team has made for Rails 3.

Rails 2 to the 3 (Abridged)
Speaker: Gregg Pollack, Envy Labs
This talk will give an overview of what has improved with a highlight reel of some of the best parts.

Why Port?
Speaker: Jeremy Kemper, 37signals
Rails 3 is the clear choice for new apps, but is it worth porting your apps running on Rails 2.3 and older?

Rack in Rails 3
Speaker: Ryan Tomayko, GitHub
In this talk we’ll take a look at Rack: why it was created, how it caught fire across Ruby web frameworks, and how to build Rack components that further extend Rails 3’s HTTP pipeline.

A recording of the conference will also be available to all participants after the event.
You will have access to it throughout the year.

SOURCE

Rails 3 Active Record usage in pills

written by silvio on January 25th, 2010 @ 07:16 PM

In Rails 3.1 passing options hash containing :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock to any of the ActiveRecord provided class methods will be deprecated, and completly removed on Rails 3.2.

The following shows a few example of the deprecated usages:

User.find(:all, :limit => 1)
User.find(:all)
User.find(:first)
User.first(:conditions => {:name => 'lifo'})
User.all(:joins => :items)

Many other useful things will be deprecated:

named_scope :red, :conditions => { :colour => 'red' }
named_scope :red, lambda {|colour| {:conditions => { :colour => colour }} }
with_scope(:find => {:conditions => {:name => 'lifo'}) { ... }
with_exclusive_scope(:find => {:limit =>1}) { ... }
default_scope :order => "id DESC"
red_items = Item.scoped_by_colour('red')
red_old_items = Item.scoped_by_colour_and_age('red', 2)

ActiveRecord in Rails 3 will have the following new finder methods:

where (:conditions)
select
group
order
limit
joins
includes (:include)
lock
readonly
from

Some examples of the new usage:

lifo = User.where(:name => 'lifo')
new_users = User.order('users.id DESC').limit(20).includes(:items)
cars = Car.where(:colour => 'black')
rich_ppls_cars = cars.order('cars.price DESC').limit(10)


Lazy Loading

As it might be clear from the examples above, relations are loaded lazily – i.e you call an enumerable method on them. This is very similar to how associations and named_scopes already work.

cars = Car.where(:colour => 'black') # No Query
cars.each {|c| puts c.name } # Fires "select * from cars where ..."

This is very useful along side fragment caching. So in your controller action, you could just do :

def index
@recent_items = Item.limit(10).order('created_at DESC')
end

And in your view :

<% cache('recent_items') do %>
<% @recent_items.each do |item| %>
...
<% end %>
<% end %>

In the above example, @recent_items are loaded on @recent_items.each call from the view. As the controller doesn’t actually fire any query, fragment caching becomes more effective without requiring any special work arounds.


New scopes

named_scope have now been renamed to just scope.

Using the method named_scope is deprecated in Rails 3.0. But the only change you’ll need to make is to remove the “named_” part. Supplying finder options hash will be deprecated in Rails 3.1.

So a definition like :

class Item
named_scope :red, :conditions => { :colour => 'red' }
named_scope :since, lambda {|time| {:conditions => ["created_at > ?", time] }}
end

Now becomes :

class Item
scope :red, :conditions => { :colour => 'red' }
scope :since, lambda {|time| {:conditions => ["created_at > ?", time] }}
end

However, as using options hash is going to be deprecated in 3.1, you should write it using the new finder methods :

class Item
scope :red, where(:colour => 'red')
scope :since, lambda {|time| where("created_at > ?", time) }
end

SOURCE

What's new in Rails 3

written by silvio on January 22nd, 2010 @ 12:56 PM


MagicPrefs

written by silvio on January 19th, 2010 @ 02:00 PM

MagicPrefs is a free menubar and preference pane application for OSX which aims to improve the functionality and configuration options of the Apple Magic Mouse.

It features the ability to bind a variable number of finger clicks, taps, swipes, pinch and other gestures to functions like Middle Click , Hold Down Both Mouse Buttons , Spaces , Expose, Dashboard etc.

Touch Sensitivity implements a single point control for a number of factors impacting the algorithms of the taps, swipes, pinch and other gestures.

Tracking Speed adds the ability to increase the maximum mouse speed by a extra 200%.

Also featured is a real-time display of the fingers touching the surface of the mouse that you can enable to test and monitor the way the mouse sees your input.

MagicPrefs.

Do One Thing for Rails 3 on January 16th and 17th

written by silvio on January 16th, 2010 @ 07:29 PM


Rails 3 is coming. Rather than run a typical BugMash where everyone attacks the Rails Core Issue Tracker, we thought we’d try something a bit different. On January 16th and 17th, we’ll be asking the Rails community to do one thing for Rails 3.

* Fix a known issue
* Report a bug
* Make sure your favorite gem or plugin still works. If not, fork it and make it so.
* Write a blog post about a certain component
* Write some documentation
* Get an app up and running and document what you had to do to upgrade.
* Create a screencast

We hope that you won’t stop at doing just one of these ideas. Do something creative to help make Rails 3 better.

We’ll announce a way for you to submit your entries later this week.

We also have a list of great prizes for anyone that participates. Your one good deed will not only help the Rails community, but it will also enter you in a raffle for these great prizes:

* $300 credit from 37signals. for Basecamp or Campfire_.
* 1 annual subscription to Less Accounting from Less Everything
* 1 year’s small plan from GitHub
* New Relic is donating 1 year of New Relic RPM Gold for 1 Host.
* BDD Casts is donating 1 15 credit pack and 3 5 credit packs which shall be awarded to 4 different participants.
* Peepcode is donating 2 credits which will be awarded to 2 different participants.
* 1 copy of the Rails Freelancing Handbook from Mike Gunderloy
* 1 copy of the Rails Rescue Handbook from Mike Gunderloy
* An ebook (3 prizes will be awarded) from the Pragmatic Bookshelf (selection excludes the Pragmatic Programmer and the SitePoint collection)
* Vinsol is donating a $50 Amazon Giftcard.

More details can be found in the BugMash Guide and the RailsBridge Wiki. Additionally, the RailsBridge team, and hopefully some Core Team members, will be available on IRC in #railsbridge on Freenode.

Do One Thing for Rails 3 on January 16th and 17th.

Add github gem repository

written by silvio on January 8th, 2010 @ 12:01 AM

To add github gem repository as a gem source just type:

sudo gem sources -a http://gems.github.com

Booting OSX 10.5 Leopard Hackintosh with grub2

written by silvio on January 7th, 2010 @ 11:23 PM

The new Grub2 os-prober script can successfully detect and confgure my triple boot system (Debian, WinXp and Osx), but my hackintosh is a bit unstable running on a multi-core cpu.

The solution is passing the cpu=1 parameter to Leopard’s kernel, but I wasn’t able to do that via the os-prober, so I created a new menuentry.

Put the following lines inside /etc/grub.d/40_custom :

menuentry "MANUAL Hackintosh OSX Leopard 10.5" {
set root=(hd0,2)
chainloader /usr/standalone/i386/chain0 cpu=1
}

Grub2 counts devices starting from 0 and partitions from 1, my hackintosh is installed on the second partition of the first drive:

  • WinXP on /dev/sda1 becomes root=(hd0,1) for grub2
  • Osx on /dev/sda2 becomes root=(hd0,2) for grub2

Just for completeness, this is my full /etc/grub.d/40_custom :

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.

menuentry "MANUAL Win XP" {
set root=(hd0,1)
chainloader +1
}

menuentry "MANUAL Hackintosh OSX Leopard 10.5" {
set root=(hd0,2)
chainloader /usr/standalone/i386/chain0 cpu=1
}

Don’t forget to run update-grub to generate the new /boot/grub/grub.cfg

mephisto_xmlrpc plugin for mephisto 0.8.2

written by silvio on January 7th, 2010 @ 01:36 PM

Installation

./script/plugin install http://svn.railshacks.com/projects/mephisto/plugins/mephisto_xmlrpc

Follow README for further installation instructions.

Source

Related

Related

UPDATE:

Follow these updated steps, the included readme is very old and instructions doesn’t work!

1: Edit file app/controllers/application/error.rb

Locate these lines

rescue_from ActiveRecord::RecordNotFound, :with => :render_admin_not_found rescue_from ActionController::UnknownController, :with => :render_admin_not_found rescue_from ActionController::UnknownAction, :with => :render_admin_not_found

Change these lines to

rescue_from ::ActiveRecord::RecordNotFound, :with => :render_admin_not_found rescue_from ::ActionController::UnknownController, :with => :render_admin_not_found rescue_from ::ActionController::UnknownAction, :with => :render_admin_not_found

Save the file.

2. Add github repo

sudo gem sources -a http://gems.github.com

3. Get the actionwebservice gem

sudo gem install datanoise-actionwebservice -v='2.2.2'

4. Add the following line to config/environement.rb

config.gem 'datanoise-actionwebservice', :version => '2.2.2', :lib => 'actionwebservice', :source => 'http://gems.github.com'

5. Restart your server

Now you have working xmlrpc service at http://YOURSITE.com/xmlrpc

Enjoy!

Hello world!

written by silvio on December 23rd, 2009 @ 11:19 AM

First post

Options:

Size

Colors