Easy Rails CI with Hudson

Link: Easy Rails CI with Hudson

Subdomains and Rails 2.1

Rails framework has many plugins for handling subdomains. One of the recommended plugins to achieve the same is Subdomain-fu.

Subdomain-fu uses Rails’s URL Writing mechanisms to provide an easy and seamless way to link and otherwise understand cross-subdomain routing.

Before attempting to know, I suggest to read a write up by Jamis Buck on understanding how rails routing works here.

Palani, my peer in Thoughtworks and I worked on implementing subdomains in our current project.

In our opinion, subdomain-fu works well as advertised, but, we had to patch up lib/subdomain_fu/routing_extensions.rb and changed the recognition_conditions_with_subdomain routine.

By default, it was taking conditions hash and we changed it to use requirements hash. The effect is that we can now pass :subdomain symbol as another parameter in map keyword of routes.rb.

The recognition_conditions_with_subdomain routine becomes like this:

def recognition_conditions_with_subdomain
result = recognition_conditions_without_subdomain
result << "requirements[:subdomain] === env[:subdomain]" if requirements[:subdomain] && requirements[:subdomain] != true && requirements[:subdomain] != false
result << "SubdomainFu.has_subdomain?(env[:subdomain])" if requirements[:subdomain] == true
result << "!SubdomainFu.has_subdomain?(env[:subdomain])" if requirements[:subdomain] == false
result
end

Routing works amazing!

the rails way of ordering models

Being a newbie to rails, I find many interesting things to do a certain operation. They call it the ruby or the rails way of doing things.

The Fine Print:

The find method, supports passing o a parameter to order based on table columns in ascending or descending order.

Example:

@users = User.find(:all)

Here @users, will have all the users in user table ordered by id.

Suppose, if we want to order by ID in reverse order., the statement becomes.,

@users = User.find(:all, :o rder => “id DESC”)

Suppose, if we want to order by AGE in reverse order, the statement becomes.,

@users = User.find(:all, :o rder => “age DESC”)

Thats it folks!

Stats

  • 142,057 Hits and counting...

Archives

Follow

Get every new post delivered to your Inbox.