1

アプリで電子メールを取得するために、(Mandrill を使用して) griddler を実装しています。

これは、メールを受信するための私のクラスです

#app/email_receivers/incoming.rb
 class EmailReceiver < Incoming::Strategies::Mandrill
   def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
   end
  end

  req = Rack::Request.new(Rails.env)
  result = EmailReceiver.receive(req) 

これは、EmailReceiver クラスの receive メソッドを呼び出す私の Rails コントローラーです。

#emails_controller.rb
 class EmailsController < ActionController::Base
   def create
    if EmailReceiver.receive(request)
     render :json => { :status => 'ok' }
    else
     render :json => { :status => 'rejected' }, :status => 403
    end
   end
 end

EmailsController の create メソッドを呼び出すルート

#routes.rb
 Rails.application.routes.draw do
   post '/emails' => 'emails#create'
 end

注:-本番環境でサーバーを実行した後

rails s -e production

このエラーが発生しました

/home/bvc-2/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/request.rb:192:in `[]=': string not matched (IndexError)

「要求を入れる」場所

req = Rack::Request.new(Rails.env) 

であることが判明:

#<Rack::Request:0xc3bace8 @env="production">

そして、私の config/application.rb ファイルは次のとおりです:-

require File.expand_path('../boot', __FILE__)

require 'rails/all'

 # Require the gems listed in Gemfile, including any gems
 # you've limited to :test, :development, or :production.
 Bundler.require(*Rails.groups)

 ActionMailer::Base.smtp_settings = {
:address =>"smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name =>  "***@gmail.com",
:password => "pass*******",
:authentication => 'plain',
:enable_starttls_auto => true
}
 module ComplaintSystem
 class Application < Rails::Application

  # Settings in config/environments/* take precedence over those specified  here.
  # Application configuration should go into files in config/initializers
  # -- all .rb files in that directory are automatically loaded.

  # Set Time.zone default to the specified zone and make Active Record    auto-convert to this zone.
  # Run "rake -D time" for a list of tasks for finding time zone names.    Default is UTC.
  # config.time_zone = 'Central Time (US & Canada)'
    config.active_job.queue_adapter = :delayed_job
    config.time_zone = 'Mumbai'
    config.active_record.default_timezone = :local
    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Do not swallow errors in after_commit/after_rollback callbacks.
      config.active_record.raise_in_transactional_callbacks = true
 end
end
4

1 に答える 1

1

stringこのタイプのエラーは、誤って変数にアクセスしようとしたときに発生しますHash

s = "hello world"
s["position"] = "programming is fun"
# > IndexError: string not matched
# > from (irb):5:in `[]='
# > from (irb):5

完全なスタック トレースを見て、そのような操作を実行しようとしている場所を確認してください。

于 2015-08-26T10:43:27.073 に答える