Archives (April 2009)



EdgeRails : rack router, protect_from_forgery & modules dependencies



Written by Anthony Heukmes on Fri Apr 17 16:16:01 UTC 2009

0 comment



The way towards Rails 3 is going on and you can find a lot of activity on GitHub these days.

First good news, Carl Lerche & Josh Peek are working on a new router (a Rack middleware, so it will not be only useful for Rails). According to Carl, performances are 2x faster than Merb router (and so, 4 times faster than Rails).

More information available on Rack GG group.

Another good news, we will not have to add authenticity tokens to our hand-written Ajax requests anymore!
You know, when you create a Javascript function that sends a POST request to your server and you get a nice "Invalid Authenticity Token" error message in return.
The solution is to add the token to your parameters or to disable CSRF attacks check in your controller using protect_from_forgery :except => :my_action.
This will not be required anymore with Rails 3!

The touch method has also been added to ActiveRecord models.
When called, it will save the record with the updated_at attribute set to the current time.

It can also be used as an option with the belongs_to association. So when the current instance is saved/destroyed, the associated object will be touched too.

belongs_to :company, :touch => true


If you follow the evolution of the Rails codebase you've probably been surprised by setup, depends_on and use keywords. You can see an example in this commit.

The source code for can be found in ActiveSupport (activesupport/ lib/active_support/core_ext/module/setup.rb) :


class Module
attr_accessor :_setup_block
attr_accessor :_dependencies

def setup(&blk)
@_setup_block = blk
end

def use(mod)
return if self < mod

(mod._dependencies || []).each do |dep|
use dep
end
# raise "Circular dependencies" if self < mod
include mod
extend mod.const_get("ClassMethods") if mod.const_defined?("ClassMethods")
class_eval(&mod._setup_block) if mod._setup_block
end

def depends_on(mod)
return if self < mod
@_dependencies ||= []
@_dependencies << mod
end
end


A cleaner way to organize modules inclusion and dependencies. Yehuda Katz wrote an article about that.

Add jQuery datagrids to your Ruby on Rails applications



Written by Anthony Heukmes on Mon Apr 13 14:53:33 UTC 2009

112 comments



It's now possible to add jQuery datagrids to your Ruby on Rails applications with just a few lines of code.

Have a look at the demo application of my new plugin : 2dcJqgrid.

Datagrids are based on a jQuery plugin and support the following features :

- Ajax-enabled
- Pagination
- Sorting
- Filters
- Multiple selections
- Master-Details
- Data manipulation (create, edit, delete)
- And more ...

Ruby : Establish a connection to an FTP server via a proxy



Written by Anthony Heukmes on Wed Apr 08 12:17:03 UTC 2009

1 comment



By default, it's not possible to connect to an FTP server via a proxy using the Net::FTP Ruby library.
To use your proxy, you have to send RAW commands to the server :

@ftp = Net::FTP.new

@ftp.connect("proxy_address")
@ftp.sendcmd("USER ftp_login@ftp_address proxy_login")
@ftp.sendcmd("PASS ftp_password")
@ftp.sendcmd("ACCT proxy_password")
@ftp.passive = true


Take the time to replace addresses and credentials by yours.
This code considers that access to your proxy server is secured by login/password.