Running rails migrations in other databases
We have a set of Ruby on Rails applications that shares user logins, so we put that table in a database and connect to it from each application.
If an app needs to add a column to the shared table, you can create a migration that accesses that other database.
First, create an entry in your database.yml file (we name ours “user_development”, etc.).
Then, establish that connection in your database migration and do your migration stuff:
This has the benefit of keeping all the migrations local to the app they’re needed for, but it stores the schema of the users table in the users database where it belongs.
Converting erb to haml in rails3
I’m taking over a project that’s just started and prefer to use haml. In setting up my environment to work with rails3 and haml, here’s the best way I found to convert the fledgling app to haml.
Install gems
Run this
This will convert all .erb files in app/views into .haml files right next to them, leaving the originals in case you need to refer to them to fix somethig the converter missed.
This isn’t rails 3 specific, except for the Gemfile part, really.
rspec2, rails3, and spork with drb to get faster tests
I started using rspec2 and rails3 on a project and wanted faster tests.
Gemfile: gem 'spork' bundle install spork --bootstrap
Bootstrapping will edit your spec_helper.rb file with some instructions. I had a vanilla spec_helper file, so everything got moved into the Spork.prefork block.
Also, I’m using autotest, so I added --drb to my .rspec file.
Finally:
spork & autotest
I only had 15 tests at the time that I did this, but they went from running in 6 seconds to running in 1.5 seconds. Significant.
UPDATE:
From the comments, here’s a fix for running rake on Windows (“can’t find executable rake”):
Using Factory Girl with Rails 3
Setting up a new project, I couldn’t get FactoryGirl working. From the README:
If you want to use factory_girl with Rails 3, see http://github.com/thoughtbot/factory_girl_rails
I added this to my Gemfile:
gem 'factory_girl_rails'
A bundle install to install and done.
Note: I’m using rspec2 and putting my factories in spec/factories/*_factory.rb and I’ve seen references to spec/support/factories/*_factory.rb as well. I’m not sure if either is the blessed location.
Overriding Rails’ automatic timestamps: updated_at & created_at
When converting something in a project, I found that I needed to updated a field for every record in a Request table. No problem, except this client grabs a SQL dump and run reports on it. So, Rails’ automatic timestamping of the updated_at field made all of the Requests look like they’d just been updated. Which they had, but not by users.
So, this rake task will reset all of them, presuming you have something to set them to. In my case, I found the latest comment date and used that, but you could figure it out some other way.
Jammit Warning: Asset compression disabled — Java unavailable (Mac/Apple)
I set up Jammit locally on my Mac running Leopard and was receiving this error:
Jammit Warning: Asset compression disabled -- Java unavailable
I checked out Java:
> java -version java version "1.5.0_22" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03-333-9M3125) Java HotSpot(TM) Client VM (build 1.5.0_22-147, mixed mode, sharing)
Odd. Poking into the jammit source, I saw that java 1.4 is required to use the YUI javascript compressor, but I had selected the google closure compiler which requires java 1.6, hence the [unclear] error message.
On Leopard, if you’ve run all your System Updates, you probably have java 1.6, but you have to select it as the default: Applications > Utilities > Java Preferences > drag new version to top
Kansas City Ruby Users: Luke Pillow on Jeweler
Luke Pillow present to the Kansas City Ruby Users Group on Jeweler and Gemcutter rubygems.org.
Also, Luke is helping to organize the Ruby Midwest conference, so you should check that out.
Kansas City Ruby Users Group | March 2010 | Luke Pillow | Jeweler for Rubygems | kcrug.org from Wes Garrison on Vimeo.
Kansas City Ruby Users: Ryan Smith on Heroku
Ryan Smith presents to the Kansas City Ruby Users Group on Heroku: why it’s wonderful for deploying Ruby on Rails applications, how to set up a new application and deploy it to Heroku in minutes, and how to use Heroku add-ons to support search.
Kansas City Ruby Users Group | March 2010 | Ryan Smith | Heroku | kcrug.org from Wes Garrison on Vimeo.
Installing sqlite headers on ubuntu (sqlite3.h not found)
I was setting up Integrity for the first time and ran into this on my server when bundling gems:
~$ bundle install ... Installing do_sqlite3 (0.10.0) from rubygems repository at http://gemcutter.org/ with native extensions /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:482:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) /usr/bin/ruby1.8 extconf.rb checking for sqlite3.h... no *** extconf.rb failed *** ...
The key is the line: checking for sqlite3.h... no
The do_sqlite3 gem gets compiled natively, but the development headers weren’t installed on the system and so the compilation won’t work.
Install them:
~$ sudo apt-get install sqlite3 ~$ sudo apt-get install libsqlite3-dev
Then, re-bundle:
~$ bundle install
Kansas City Ruby User Group: Kyle J Ginavan on Progressive Enhancement
Presentation: Kyle Ginivan on Progressive Enhancement
Progressive enhancement is a strategy for web design that emphasizes accessibility, semantic markup, and external stylesheet and scripting technologies. Progressive enhancement uses web technologies in a layered fashion that allows everyone to access the basic content and functionality of a web page, using any browser or Internet connection, while also providing those with better bandwidth or more advanced browser software an enhanced version of the page.
read more

Posted by Wes in