Fork me on GitHub

error_messages_for is_no_more

by Phil

Worth noting that error_messages_for is not included, by default, in Rails 3. If you check your console server log you'll see this warning:-

DEPRECATION WARNING: error_messages_for was removed from Rails and is now available as a plugin. 
Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`.

After you install the plugin, everything works as expected.



Posted on Sun 16 May 2010 | Comments

Issue with localhost subdomains in Rails 3

by Phil

While upgrading one of my Rails 2.3 apps to Rail 3, I came across a few issues when using subdomains with a localhost domain. I have a route like so:-

 root :to => 'controller#page', :constraints => {:subdomain => "subdomain1"}

I had a test subdomain set-up in my /etc/hosts file as usual. For instance, here is the first line in my /etc/hosts file:-

 127.0.0.1  subdomain1.localhost

So, if I request the url http://subdomain1.localhost:3000, Rails 3 treats "subdomain1.localhost" as the domain. In other words, it is treating "localhost" as the TLD.

To fix this I changed my test subdomain, in the /etc/hosts file, to have a TLD, like so:-

 127.0.0.1  subdomain1.localhost.local

And hey presto, as if by magic, it now works.

UPDATE: Changed TLD to .local (makes more sense)



Posted on Sun 09 May 2010 | Comments

Compass CSS3 Cross-Browser Mixins

by Phil

I've been having a great time using Compass when working on meetee recently. In particular, I've been making use of the CSS3 mixins.

The mixins for Text Shadow, Box Shadow and Gradient have been really useful. No need to worry about any cross-browser compatibility issues - compass takes care of this for you. Plus you're left with more concise code.

The new documentation is looking really nice as well! Highly recommended.



Posted on Tue 04 May 2010 | Comments

Using Rack Middleware in Rails3

by Phil

I was just looking into including some Rack middleware in my Rails 3 app. One thing confused me slightly. There seems to be two ways that you can include middleware in you app:-

1. config.ru

2. application.rb

Note: I'm using the codehighlighter rack middleware for this example.

I'm not sure what is the recommended way, however, I think it seems best placed in the config.ru file (since this file is directly related to Rack). In the Rails edge documentation it says that you should use the config.middleware method in the "environment.rb" file... surely this couldn't be right?



Posted on Wed 17 Feb 2010 | Comments

Disable ActiveRecord in Rails 3

by Phil

Came up against this recently when trying to upgrade a Rails app which was using MongoDB. Obviously I didn't want to use ActiveRecord, so I set about removing it.

The old way of removing ActiveRecord was to place this line in the environment.rb file, "config.frameworks -= [ :active_record ]". However, in Rails 3 you can simply pass the "-O" switch to the rails command, like so:-

 rails yourapp -O

But what if you've already created your app? If you look in your config/application.rb file, you'll see this line at the top:-

 require 'rails/all'

This does what it says on the tin; includes all rails modules. If you want to exclude ActiveRecord, remove the above line and replace it with:-

 # Pick the frameworks you want:
 # require "active_record/railtie"
 require "action_controller/railtie"
 require "action_mailer/railtie"
 require "active_resource/railtie"
 require "rails/test_unit/railtie"

This is the beauty of Rails 3, pick and choose what suits you.



Posted on Fri 12 Feb 2010 | Comments
© 2009 Phil McClure This site was developed using Compass, Blueprint and Ruby on Rails - Much thanks to these guys!