NoMethodError:未定义的方法`const_defined?'在提到类方法时

时间:2014-11-26 17:36:15

标签: ruby-on-rails ruby

我正在构建一个电子邮件发送系统到已经相当复杂的rails应用程序中。 从控制器我尝试调用构建电子邮件然后传递它的方法。

在控制器中:

response_for :create, :update do
  estimate = current_object.estimate.reload
  flash[:success] = "Tier Save Successful. " 
  flash[:success] += send_estimate_email if estimate.verify && estimate.tiers.select{|t| !t.verified?}.empty?
  flash[:notice] = "This service bundle was changed for a previously verified service bundle.  Please re-verify after changes are complete" if current_object.auto_unverified
  redirect_to [current_object.estimate]
end

def send_estimate_email
    return "" if current_object.estimate.requestor_email.blank? || !current_object.estimate.requestor_notified_at.blank?
    begin
      estimate = current_object.estimate
      host = request.host_with_port
      binding.pry
      success = EstimateEmailer.deliver_verification_complete(estimate, host)
      current_object.estimate.notes.create!(:user_id => User.find(:first, :conditions => {:user_type_id => UserType::ROOT.id}).id, :title => "Verification Complete Email Sent", :body => "TO: #{success.to}\nSUBJECT: #{success.subject}\nBODY: #{success.body}")
    rescue Exception => e
      logger.warn(e)
      success = false
    end
    if success
      current_object.estimate.update_attribute(:requestor_notified_at, Time.now)
      current_object.estimate.notes.create!(:title => "Auto-email sent to requestor", :body => "TO: #{success.to}\nSUBJECT: #{success.subject}\nBODY: #{success.body}", :user_id => current_user.id)
      return "Automatic estimate email was successfully sent to #{current_object.estimate.requestor_email}"
    else
      return "However, automatic estimate email could not be sent due to an error"
    end
  end

我不认为电子邮件代码本身有任何问题,但由于某种原因,我在EstimateEmailer.deliver_verification_complete(estimate, host)电话上收到此错误:

NoMethodError: undefined method `const_defined?' for "estimate":String

在EstimateEmailer调用之前在控制器中设置断点我注意到每当我尝试引用其他类时都会收到错误。只是调用EstimateEmailer或任何其他类名返回相同的错误。

我过去曾遇到undefined method const_defined?的问题。我猜这个问题不是特定于发送电子邮件,但我还没有想到从哪里开始调试。

  def verification_complete(estimate, host)
    request_id = estimate.integration_transactions.empty? ? "Internal ID #{estimate.id}" : estimate.integration_transactions.last.source_id
    @estimate = estimate
    @estimate_url = public_estimate_url(estimate.public_id, :host => host, :protocol => 'https')
    mail(
      subject: "Ref ##{estimate.project_code} Application Hosting Estimate Available for Review: #{request_id}",
      to: [estimate.requestor_email, estimate.project_manager_email].reject{|email| email.blank? }.join(','),
      from: SUPPORT_ADDRESS
    )
  end

1 个答案:

答案 0 :(得分:0)

您正在使用与当前版本的ActiveSupport不兼容的make_resourceful。我刚刚提出了解决它问题的公关:https://github.com/hcatlin/make_resourceful/pull/16

或者,您可以指向Gemfile中的远程分支:

gem 'make_resourceful', github: 'carpodaster/make_resourceful', branch: 'fix/incompatibility-with-active-support-dependencies'

我认为这个问题只发生在您的开发环境中,对吧?在这种情况下,您应该可以通过在config.eager_load = true中设置config/environments/development.rb来避免它。