2013-12-09 2 views
0

저는 Ruby on Rails를 처음 사용하고 있으며 현재 Michael Hartl 튜토리얼을 통해 실행 중입니다. 어떤 메서드를 호출 할 때 미친 긴 오류가 발생하기 시작했습니다. 어느 것이 상관 없어요.방법 없음 오류 - 정의되지 않은 메서드 'chomp'

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/[email protected]_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load' 
from /usr/local/rvm/gems/[email protected]_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/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `each' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `block in <class:Engine>' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run' 
from /usr/local/rvm/gems/[email protected]_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/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `each' 
from /usr/local/rvm/gems/[email protected]_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/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!' 
from /usr/local/rvm/gems/[email protected]_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/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require' 
from /usr/local/rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!' 
from /usr/local/rvm/gems/[email protected]_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 

답변

1

chompto_s로 교체 ('. 비밀') 데프 \t token_file = Rails.root.join을 secure_token

File.read token (token_file).to_s

+0

가' '의 SecureRandom를'필요 \t if File.exist? (token_file) 기존 토큰 (여기에 라인 18 시작) #Use \t \t \t \t File.read 토큰 (token_file) 새로운 토큰 다른 \t \t \t #Generate .chomp 및 token_file에 저장합니다. 여기서 SampleApp :: Application.config.secret_key_base = secure_token ' – Brandoshmando

+0

가 편집 할 수 \t \t 토큰 = SecureRandom.hex (64) \t \t file.write가 (토큰 token_file) \t \t 토큰 \t 끝 최종 사용자 이 정보 대신에 질문. – Kaleidoscope

+0

죄송합니다. 스택 오버플로도 새로 도입되었습니다. – Brandoshmando

관련 문제