Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Matt Scilipoti

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Howto: setup the rails environment in a .rb script

Stolen from: http://www.railsonwave.com/railsonwave/2007/2/14/howto-setup-the-rails-environment-in-a-rb-script
I quote:

It can happen that you need to perform some operations on your rails application from a script, for example you may need to have a cron job that do something on your models. To archieve this goal you need to set up a rails environment in your script; it’s really easy, you’ve just to put these lines on the top of your .rb file.
RAILS_ROOT = RELATIVEPATHTOYOURAPPFOLDER
require RAILS_ROOT + "/config/environment" 
Dependencies.load_file("application.rb")

I really don’t know why but you have to manually load application.rb, if you don’t rails translate the ‘ApplicationController’ constant into ‘application_controller’ and look for a file named ‘application_controller.rb’ that doesn’t exist.

Sandro.

From the comments:
edbond says:
for script in your RAILS_ROOT folder
ENV['RAILS_ENV'] = 'development' require File.expand_path(File.dirname(__FILE__) + "/config/environment")


// insert code here..

Windows Start|Run magic

Stolen from: http://www.hanselman.com/blog/Reflector5ReleasedWorldDominationAssured.aspx

Tuesday, February 20, 2007 1:18:12 PM (Pacific Standard Time, UTC-08:00)
The PATH might make sense if you have a single folder with a bunch of utilities. Otherwise, you can safely leave your DOS tricks behind and just add an entry for reflector.exe to:
HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths

Set the (Default) string value to the full path to the executable. Start|Run glory, the Windows way.
Joshua Flanagan

Windows Path

Stolen From: http://www.hanselman.com/blog/Reflector5ReleasedWorldDominationAssured.aspx
Tuesday, February 20, 2007 4:54:50 PM (Pacific Standard Time, UTC-08:00)

You mention that reflector should be in your path. That gives me an opportunity to exploit a (ruby) gem I created a few weeks ago which makes managing your path a breeze. Instead of going to My Computer | Properties | Blah blah and adding the path entry using that terrible dialog, just follow these steps:
gem install patheditor
path_editor --add c:\path\to\reflectore

Adding items to the Windows Path is so painful, I created this utility to make it a little easier for everyone.

It uses a WSH object to update your USER path setting, and the change will be permanent - current and future command prompts will see the new path. Unfortunately, slickrun does not respect path updates so you'll have to kill it and restart if you launch prompts from there ...
Justin

Also:
Thursday, February 22, 2007 5:25:22 PM (Pacific Standard Time, UTC-08:00)
@Jon

Updating path that way (Set PATH=) only affects your current command prompt. My script uses WSH objects to propagate the change to all running processes (that respect the update), and future prompts will include the new path.

The script will also not add duplicate entries, and it can even clean duplicate/non-existent directories out of your current path.
Justin
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS