Method: Mongrel::Rails::RailsConfigurator#rails
- Defined in:
- lib/mongrel/rails.rb
#rails(options = {}) ⇒ Object
Creates a single rails handler and returns it so you can add it to a URI. You can actually attach it to as many URIs as you want, but this returns the same RailsHandler for each call.
Requires the following options:
-
:docroot => The public dir to serve from.
-
:environment => Rails environment to use.
-
:cwd => The change to working directory
And understands the following optional settings:
-
:mime => A map of mime types.
Because of how Rails is designed you can only have one installed per Ruby interpreter (talk to them about thread safety). Because of this the first time you call this function it does all the config needed to get your Rails working. After that it returns the one handler you’ve configured. This lets you attach Rails to any URI(s) you want, but it still protects you from threads destroying your handler.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/mongrel/rails.rb', line 133 def rails(={}) return @rails_handler if @rails_handler ops = resolve_defaults() # fix up some defaults ops[:environment] ||= "development" ops[:docroot] ||= "public" ops[:mime] ||= {} $orig_dollar_quote = $".clone ENV['RAILS_ENV'] = ops[:environment] env_location = "#{ops[:cwd]}/config/environment" require env_location require 'dispatcher' require 'mongrel/rails' ActionController::AbstractRequest.relative_url_root = ops[:prefix] if ops[:prefix] @rails_handler = RailsHandler.new(ops[:docroot], ops[:mime]) end |