Merb rake tasks

Thursday 11/27/2008  –  Category: Merb  –  No Comments

When trying to run a merb rake task I wrote, I ran across this error:

rake aborted!
Don't know how to build task 'environment'

It turns out that merb uses a different environment variable than Rails,  so instead of :environment use :merb_env instead:

task :whatever => :merb_env do

merb and Twitter made easy with Twitter4R

Wednesday 11/26/2008  –  Category: Merb  –  No Comments

Updating twitter with merb is super easy with Twitter4R:

sudo gem install twitter4r

in config/dependencies.rb:

gem "twitter4r"
require 'twitter'

(just doing dependency "twitter4r" didn't work)

in your controller:

client = Twitter::Client.new(:login => 'username', :password => 'password')
status = client.status(:post, "hello world")

Strange errors when upgrading merb

Wednesday 11/26/2008  –  Category: Merb  –  No Comments

I had some strange errors when upgrading to the latest version of merb (1.1.3).  When trying to run

rake db:automigrate

I would get something like:

~ Connecting to database...
/opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:137:in `initialize': wrong number of arguments (8 for 1) (ArgumentError)
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:137:in `new'
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:137:in `normalize_uri'
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/abstract_adapter.rb:44:in `initialize'
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/adapters/data_objects_adapter.rb:159:in `initialize'
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core.rb:157:in `new'
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core.rb:157:in `setup'
from /opt/local/lib/ruby/gems/1.8/gems/merb_datamapper-1.0/lib/merb/orms/data_mapper/connection.rb:44:in `setup_connections'
from /opt/local/lib/ruby/gems/1.8/gems/merb_datamapper-1.0/lib/merb/orms/data_mapper/connection.rb:27:in `connect'
from /opt/local/lib/ruby/gems/1.8/gems/merb_datamapper-1.0/lib/merb_datamapper.rb:17:in `run'
from /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0/lib/merb-core/bootloader.rb:99:in `run'
from /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0/lib/merb-core/server.rb:172:in `bootup'
from /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0/lib/merb-core/server.rb:42:in `start'
from /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0/lib/merb-core.rb:169:in `start'
from /opt/local/lib/ruby/gems/1.8/gems/merb-core-1.0/bin/merb:11
from /opt/local/bin/merb:19:in `load'
from /opt/local/bin/merb:19

After googling for awhile I found this post that suggested downgrading the addressable gem back to 1.0.4.  I tried doing that but stuff was still acting funky, it would say

FATAL: The gem dm-core (= 0.9.7, runtime), [] was not found

even though it was still there.  For some reason, doing sudo gem uninstall merb didn't clean up all the merb+other dependencies, so I had to start of clean by removing merb and all its dependencies:

sudo gem uninstall addressable data_objects datamapper dm-aggregates dm-migrations dm-sweatshop dm-timestamps dm-types dm-validations do_mysql do_sqlite3 merb-action-args merb-assets merb-auth merb-auth-core merb-auth-more merb-auth-slice-password merb-cache merb-core merb-exceptions merb-gen merb-haml merb-helpers merb-mailer merb-more merb-param-protection merb-slices merb_datamapper

After installing one more time, everything worked fine and dandy.  Sheesh, why can 'sudo gem update merb' play nice out of the box?

Using Monit to…monitor stuff

Tuesday 11/25/2008  –  Category: Uncategorized  –  No Comments

Monit is a useful tool that lets you monitor your server and run commands based on certain variables (ex: restart your mongrel instances if they grow > x MB).  Plus, it comes with a nice web interface to quickly see your load averages and memory usage (easier than logging in and running top).

I've liked using Phusion Passenger as a stupid-easy deployment solution for Rails (and now merb) apps, but running three Rails apps and one Merb app on a Slicehost 256slice, things got kind of crowded.  I had to set the PassengerMaxPoolSize variable to 2 in order to keep my free memory at an acceptable level, and I got annoyed when Passenger would automatically kill my apps after a certain amount of idle time or when another app was started up.  Though things were generally zippy once the instances were loaded, there was a laggy startup time while spawning the new app.

Because of this, I decided to take another shot at deploying with mongrel+nginx--I had used it for a site awhile back but had gotten lazy.  It turns out that nginx (a super-fast lightweight web server) is a lot easier and less confusing to setup and configure than Apache...and after setting up the reverse proxy stuff my Rails/Merb apps were humming along smoothly.

Another cool thing about nginx is that it serves static assets (stylesheets/js/images/etc) really fast.  To take advantage of this on my blogs, I installed WP Super Cache (following this howto) to generate static files.  This speeds up load time since Wordpress doesn't have to hit the database at all once a page is cached.

Overall I'm happy with the move to nginx/mongrel...and now my server is running 30% free memory (as compared to just a few MB to spare with my previous setup).

 Page 11 of 14  « First  ... « 9  10  11  12  13 » ...  Last »