mardi 30 mai 2017

Rails 5/Ember-CLI-Rails - NoMethodError (private method `require' called for #

In Rails 5, we're receiving NoMethodError (private method 'require' called for #<ActiveSupport::HashWithIndifferentAccess when calling something simple in a controller like params.require(:key). This endpoint is triggered from an Ember CLI rails page (not sure if it's the reason).

I know it's been deprecated, and am suspecting some middleware, but I've removed a lot and so far it hasn't helped.

rake middleware yields:

Michaels-MBP-2:mvp mycomp$ rails -v
rake Rails 5.0.1
Michaels-MBP-2:mvp mycomp$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
Michaels-MBP-2:mvp mycomp$ rake middleware
use Rack::Sendfile
use ActionDispatch::Static
use ActionDispatch::Executor
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use RequestStore::Middleware
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use Airbrake::Rack::Middleware
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use Warden::Manager
use ParamsTester
use Rack::Cors
run My::Application.routes

ParamsTester is my middleware trying to determine when params is being converted to a hash, which looks like this in lib/params_tester.rb and is returning PARAMS NOT SET

VALID_LOG_LEVELS = [:debug, :info, :warn, :error, :fatal, :unknown]

class ParamsTester
  def initialize app, log_level
    @app = app
    # Default to :info log level if the user sets an invalid log level.
    @log_level = VALID_LOG_LEVELS.include?(log_level) ? log_level : :warn
  end

  def call env
    dup._call env
  end

  def _call env
    request_started_on = Time.now
    @status, @headers, @response = @app.call(env)
    request_ended_on = Time.now

    Rails.logger.send(@log_level, '=' * 50)
    Rails.logger.send(@log_level, "Request delta time: #{request_ended_on - request_started_on} seconds.")
    begin
      Rails.logger.send(@log_level, 'PARAMS: ' + request ? request.parameters.class : ' NO REQUEST PARAMS')
    rescue
      Rails.logger.send(@log_level, 'PARAMS NOT SET')
    end
    Rails.logger.send(@log_level, '=' * 50)

    [@status, @headers, @response]
  end
end




Aucun commentaire:

Enregistrer un commentaire