我是Ruby on Rails的新手,目前正在运行Michael Hartl教程。在尝试调用任何方法时,我开始遇到一个疯狂的长错误。没关系哪个。以下是运行:
rails generate controller StaticPages about --no-test-framework
然后我收到以下错误:
/Users/MYUSERNAME/rails_projects/sample_app/config/initializers/secret_token.rb:18:in `secure_token': undefined method `chomp' for #<Pathname:/Users/MYUSERNAME/rails_projects/sample_app/.secret> (NoMethodError)
from /Users/bcraft07/rails_projects/sample_app/config/initializers/secret_token.rb:27:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `block in <class:Engine>'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:209:in `block in each_strongly_connected_component_from'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `tsort_each_child'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/bcraft07/rails_projects/sample_app/config/environment.rb:5:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!'
from /usr/local/rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.2/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
我的假设是与我的RVM和我拥有的宝石有关。我知道这是一个很长的错误,很多都是我正在处理的项目所特有的,但是我们非常感谢任何帮助。请记住,我是严肃的菜鸟!
编辑:
require 'securerandom'
def secure_token
token_file = Rails.root.join('.secret')
if File.exist? (token_file)
#Use the existing token
File.read token (token_file).chomp
else
#Generate a new token and store it in token_file.
token = SecureRandom.hex(64)
File.write(token_file, token)
token
end
end
SampleApp::Application.config.secret_key_base = secure_token
答案 0 :(得分:1)
将chomp
替换为to_s
:
File.read token (token_file).to_s