views:

33

answers:

2

I want to start up my Rails development server like this:

script/server OFFLINE_MODE=1

and have a method in application_controller.rb that checks for the presence of that constant:

helper_method :offline_mode?
def offline_mode?
  defined?(OFFLINE_MODE) ? true : false
end

so I can hide stuff in my app when I'm coding without access to the internet. For some reason though, OFFLINE_MODE doesn't ever seem to be defined and the method always returns false.. thoughts?

+2  A: 

Try this:

script/server offline foo bar

Your helpers

helper_method :offline_mode?, :foo?
def offline_mode?
  ARGV.include?('offline')
end

# another example
def foo?
  ARGV.include?('foo')
end
macek
Sweet! That didn't quite work but led me down the right path: http://zeke.tumblr.com/post/501363554/rails-on-a-plane
Zeke
@Zeke, yea I had a mistake at first. I fixed my code example :)
macek
+3  A: 

You could use an environment variable to do this:

OFFLINE_MODE=1 script/server

def offline_mode?
    defined?(ENV['OFFLINE_MODE']) ? true : false
end
rjh
The obvious advantage is that you can `export OFFLINE_MODE=1` once for your session, then all commands will have that environment var set.
rjh