learn-ruby-on-rails

Learn Ruby on Rails book: email configuration using TextEdit


I was on page 147 (epub) of Kehoe's Learn Ruby on Rails book and copied this code to config/environments/development.rb:

config.assets.debug = true
   config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: Rails.application.secrets.domain_name,
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: Rails.application.secrets.email_provider_username,
    password: Rails.application.secrets.email_provider_password
  }

However, after that and trying to run server I get this:

Boruckis-MacBook-Air:learn-rails szymonborucki$ rails s
=> Booting Thin
=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:370:in `parse': (<unknown>): could not find expected ':' while scanning a simple key at line 15 column 1 (Psych::SyntaxError)
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:318:in `parse'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:245:in `load'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/application.rb:325:in `secrets'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/config/environments/development.rb:32:in `block in <top (required)>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/railtie.rb:210:in `instance_eval'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/railtie.rb:210:in `configure'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/config/environments/development.rb:1:in `<top (required)>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/engine.rb:594:in `block (2 levels) in <class:Engine>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/engine.rb:593:in `each'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/engine.rb:593:in `block in <class:Engine>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/initializable.rb:44:in `each'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `call'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /Users/szymonborucki/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/config/environment.rb:5:in `<top (required)>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/config.ru:3:in `block in <main>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/config.ru:in `new'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/config.ru:in `<main>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands/server.rb:50:in `app'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands/server.rb:130:in `log_to_stdout'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands/server.rb:67:in `start'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:81:in `block in server'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/bin/rails:8:in `require'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/bin/rails:8:in `<top (required)>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
    from /Users/szymonborucki/.rvm/gems/ruby-2.1.2@learn-rails/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/bin/spring:16:in `require'
    from /Users/szymonborucki/ruby_apps/workspace/learn-rails/bin/spring:16:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

I followed the tutorial to the letter, have Ruby 2.1.2 and Rails 4.1.4 installed. What should I do to get through it? I tried using the files from book's GitHub repo but result is the same. Here is the project:

https://github.com/SimonBo/learn-rails.git

Solution

  • The stack trace indicates the failure is in line 32 of config/environments/development.rb.

    Try replacing domain: Rails.application.secrets.domain_name with:

    domain: "example.com",
    

    You'll need quotes and a comma.

    If you get a subsequent failure on line 36 (as you report), replace:

    user_name: "my_user_name",
    password: "my_password"
    

    You've got a problem with the config/secrets.yml file not set up properly. If your config/secrets.yml file sets the domain value with an environment variable, it's likely your environment variables are not set properly. If you have trouble setting Unix environment variables, you can add credentials directly to the config/secrets.yml file. If you do so, you should not check the file into Git until you’ve deleted the secrets from the file.