The ELC Community Blog
A knowledge exchange on Ruby on Rails and Agile Development
Environment Scripts in merb
by josh on January 22, 2008
The time has come to run a script using cron or another background worker and I find myself reaching for script/runner only...
It's not there!
No worries...here's what you do:
#!/usr/bin/env ruby require 'rubygems' require 'merb' require File.dirname(__FILE__) + '/../config/dependencies' load_paths = [] load_paths.unshift(File.join(Merb.root , '/app/models')) # add more load paths here, such as # load_paths.unshift(File.join(Merb.root , '/app/controllers')) load_paths.each do |path| Dir.glob("#{path}/*").each { |m| require m } end
You can avoid everything from line 4 onward by using Merb::BootLoader.load_application but it will load the routes, which takes longer.
Check in your merb gem (lib/merb/boot_loader.rb) for more help.
Also posted to fr.ivolo.us
Timeline
- Executing Shell Commands in Ruby
- Tutorial - Red5, AS3, FC4, and Shared Fridge Magnets!
- Setting up a Flash Media Server on EC2 (CentOS)
- AWS/S3 may cause rake task failed
- Refreshing Rails Generated Views
- Environment Scripts in merb
- Script Terminal with TermInit
- Patching Rails - Rendering form partials
- Open Social plugin progress report
- Notify me when it's done
- OpenSocial on Rails, finally 1.0
Comments