xxyyxx
xxyyxx

Reputation: 2396

Can't get rails server to start

When I try to start my rails server in the environment "mainstreet" this function in my config/site_config.rb file

def self.settings(env)
    answer = YAML::load_file('config/siteconfig.yml')[env]
    raise "No settings for environment #{env}" if answer.nil?
    answer
end

returns "No settings for the environment mainstreet" In siteconfig.yml I have:

mainstreet:
environment: mainstreet
S3_DOC_BUCKET: 
PPTX_GEN_SERVICE:
PDF_GEN_SERVICE: 
OBJ_THUMB_SERVICE: 
WINDOWS_CLIENT_URL: 
KM_KEY:
HOST_NAME: http://localhost:3000

and I have a mainstreet.rb file in /config with settings defined. I'm new to ruby, so I'm not sure whats going on here, I've never had an issue like this. Also, I'm using windows.

Here's the full trace:

Upvotes: 0

Views: 131

Answers (1)

Jeff Paquette
Jeff Paquette

Reputation: 7127

Sounds like the current directory isn't what you think it is...You need to specify the full path to your config file:

def self.settings(env)
    path = File.join(Rails.root, "config", "siteconfig.yml")
    answer = YAML::load_file(path)[env]
    raise "No settings for environment #{env}" if answer.nil?
    answer
end

EDIT: Your config file is badly formatted, if what you have here is correct. It should be indented:

mainstreet:
    environment: mainstreet
    S3_DOC_BUCKET: 
    PPTX_GEN_SERVICE:
    PDF_GEN_SERVICE: 
    OBJ_THUMB_SERVICE: 
    WINDOWS_CLIENT_URL: 
    KM_KEY:
    HOST_NAME: http://localhost:3000

In a rails3 console, the file parses correctly:

irb(main):039:0> y = YAML.load_file("c.yml")["mainstreet"]
=> {"environment"=>"mainstreet", "S3_DOC_BUCKET"=>nil, "PPTX_GEN_SERVICE"=>nil, "PDF_GEN_SERVICE"=>nil, "OBJ_THUMB_SERVICE"=>nil, "WINDOWS_CLIENT_URL"=>nil, "KM_KEY"=>nil, "HOST_NAME"=>"http://localhost:3000"}

This assumes you're passing "mainstreet" as the value of env in your function

Upvotes: 1

Related Questions