【问题标题】:Internal Server Error: undefined method `symbolize_keys' for #<String:0x0000000589bde0>内部服务器错误:#<String:0x0000000589bde0> 的未定义方法“symbolize_keys”
【发布时间】:2015-02-17 00:35:50
【问题描述】:

我讨厌问一个看起来已经被问过很多次的问题,但我的情况似乎有所不同。我使用 nitrous.io 作为我的开发环境,当我尝试预览我的应用程序时,我收到此错误消息。

跟踪是: 错误 NoMethodError:未定义的方法 symbolize_keys' for #<String:0x0000000476d9b0>
/home/action/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/application.rb:327:in
secrets'
/home/action/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/application.rb:461:in validate_secret_key_config!'
/home/action/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/application.rb:195:in
env_config'
/home/action/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/engine.rb:510:in call'
/home/action/.rvm/gems/ruby-2.1.5/gems/railties-4.1.8/lib/rails/application.rb:144:in
call'
/home/action/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/lock.rb:17:in call'
/home/action/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/content_length.rb:14:in
call'
/home/action/.rvm/gems/ruby-2.1.5/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in service'
/home/action/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in
service'
/home/action/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in run'
/home/action/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in
block in start_thread'

我想我的密钥有问题,但我不知道是什么问题。我什至不知道还有什么其他信息可以放在这里!

如果有人有任何想法,我会很感激您的意见。 . .

【问题讨论】:

  • 正如 Finks 在某处提到的那样,当您应该传递哈希时,您正在传递字符串。你能发布你的密钥的格式吗(显然不要发布密钥。)
  • 尝试使用rake secret 生成一个新密钥,然后复制并粘贴到您的config/secrets.yml

标签: ruby-on-rails nitrousio


【解决方案1】:

SPACE - 您的问题是缺少空格字符。

WRONG: secret_key_base:afcb44c
CORRECT: secret_key_base: afcb44c

检查你的 config/secrets.yml,它应该是这样的:

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

production:
  secret_key_base: 59834597551c797b02cd5bb3edd7439f7a9c604bc82531d51d6e5f995e6ea849deb545df53213c5fd2ce4d698edfca65c8aa1b4e0fbadd884efefae0348b079b

development:
  secret_key_base: aea4705f645128e053daf1f8511014aca3b1e28323c3ece75f228540fb310869a6c4aeac172783d1c5c8ec9c5fe9b7f7af9a0204714db29e1d2a6709fca65ebf

test:
  secret_key_base: afcb44cfa8eab1f23d19b87e327d0fcc42e7c1d2c681812b346b57901ddb2511ebde569a1b868da367e2de14554c648f723a30de3daada015bbd0b268beeda3b

# Do not keep production secrets in the repository,
# instead read values from the environment.
# production:
#   secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

另外,如果您需要生成新密钥,请使用以下命令:rake secret

所以请不要忘记在“:”之后添加一个空格。

【讨论】:

  • 空间让一切变得不同!
【解决方案2】:

symbolize_keys 方法是一种期望请求具有Hash 数据类型的方法,但您的请求却具有string。所以仔细检查你的代码。

【讨论】:

  • 这是导致此类错误的主要原因 - 这不是具体案例 - 干得好,伙计
猜你喜欢
  • 1970-01-01
  • 2016-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-24
  • 2015-02-22
  • 2015-08-23
  • 1970-01-01
相关资源
最近更新 更多