我正在关注来自 http://learn-rails.com/ 的 learn-rails 教程书 2

I'm following the learn-rails tutorial book 2 from http://learn-rails.com/

我是初学者!

当我启动 rails server:

时,我在终端中不断收到此错误
rails server localhost:3000

Exiting
/Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/rack-1.6.4/lib/rack/handler.rb:78:in `require': cannot load such file -- rack/handler/localhost:3000 (LoadError)
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/rack-1.6.4/lib/rack/handler.rb:78:in `try_require'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/rack-1.6.4/lib/rack/handler.rb:16:in `get'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/rack-1.6.4/lib/rack/server.rb:290:in `server'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:125:in `print_boot_information'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/commands/server.rb:75:in `start'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/michael/Projects/RailsApps/learn-rails/bin/rails:9:in `require'
    from /Users/michael/Projects/RailsApps/learn-rails/bin/rails:9:in `<top (required)>'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/bin/spring:49:in `<top (required)>'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
    from /Users/michael/Projects/RailsApps/learn-rails/bin/spring:13:in `require'
    from /Users/michael/Projects/RailsApps/learn-rails/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

我使用的是 2013 款 MacBook Air 运行 OSX EL Cap 10.11.6 rvm 1.27.0 ruby2.3.1 rails 4.2.5 我是来自 Projects/RailsApps/learn-rails 的 运行 rails 服务器。我正在学习第 10 章的配置,并在 .bashrc 中设置了我的环境变量,并配置了 config/secrets.yml 文件以从环境变量中提取。 我曾尝试使用谷歌搜索寻求帮助,但找不到任何相关的答案。 我也无法在 SO 或 Quora 上找到可以帮助我的答案。

**更新 这是我在 运行 'bundle' 和 'rails g simple_form:install'

之后收到的错误消息
Michaels-MacBook-Air:learn-rails michael$ rails g simple_form:install
[Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
/Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/erb.rb:864:in `eval': (erb):15: syntax error, unexpected '=', expecting end-of-input
;  =ENV["SENDGRID_PASSWORD"] ; _e...
    ^ (SyntaxError)
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/erb.rb:864:in `result'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/application.rb:391:in `secrets'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/application.rb:178:in `key_generator'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/application.rb:206:in `message_verifier'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/globalid-0.3.7/lib/global_id/railtie.rb:25:in `block (2 levels) in <class:Railtie>'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
    from /Users/michael/Projects/RailsApps/learn-rails/config/environment.rb:5:in `<top (required)>'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/application.rb:92:in `require'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/application.rb:92:in `preload'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/application.rb:143:in `serve'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
    from /Users/michael/.rvm/gems/ruby-2.3.1@learn-rails/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/michael/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

我检查了我的 gemfile。 gem simple_form 已从 gemfile 中列出并取消注释。

我认为在你的 secrets.yml 文件中,你有这样的东西。

<% =ENV["SENDGRID_PASSWORD"] %>

=ENV["SENDGRID_PASSWORD"] 不是有效的 ruby 表达式,这就是您收到错误的原因。

其实应该是

<%= ENV["SENDGRID_PASSWORD"] %>

希望对您有所帮助!