【问题标题】:uninitialized constant ActiveSupport::Json despite "require 'active_support/all'"未初始化的常量 ActiveSupport::Json 尽管“需要'active_support/all'”
【发布时间】:2015-08-29 20:44:19
【问题描述】:

我在我的小型 Rails 应用程序的一个小型控制器中调用 responseJson = ActiveSupport::Json.decode(response) 的那一行收到“未初始化的常量 ActiveSupport::Json”错误。

response 变量返回带有{"token":"this_is_your_session_token"} 类型响应的字符串。

我已将gem 'activesupport', '~> 4.2.3' 添加到我的Gemfile,尝试使用'active_support/core_ext/object/json 使用不同的require 语句,并在IRB 中尝试了此操作(错误相同)。我不确定如何进一步调试。任何帮助将不胜感激。

需要'active_support/json'

require 'active_support'
require 'active_support/all'
require 'rest-client'

class WelcomeController < ApplicationController
  def login_attempt
    username = params[:u]
    password = params[:p]

    puts "waiting on request"
    response = RestClient.post 'http://localhost:3001/v1/login', :email => username, :password => password
    responseJson = ActiveSupport::Json.decode(response)
  end

end

【问题讨论】:

    标签: ruby-on-rails ruby json rest-client activesupport


    【解决方案1】:

    ActiveSupport::JSON(全部大写)。仅供参考,如果您使用 pry 而不是 irb,您可以运行类似“ls ActiveSupport”的命令并查看包含的模块、方法等。

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 2011-10-14
      • 1970-01-01
      • 2011-07-30
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      相关资源
      最近更新 更多