NoMethodError (неопределенный метод `new_payment_model 'для nil: NilClass) в ROR версии 2 - PullRequest
0 голосов
/ 15 мая 2018

У меня ошибка лица в ROR версии 2, NoMethodError (неопределенный метод `new_payment_model 'для nil: NilClass), вот мой код

class Authorization < ActiveRecord::Base
  belongs_to :franchisee
  belongs_to :deleted_by, :class_name => 'User', :foreign_key => :deleted_by
  belongs_to :created_by, :class_name => 'User', :foreign_key => :created_by
  has_many   :transactions
  validates_presence_of :notify_email
  validates_presence_of :activation_price, :expires_on
  validates_length_of :notify_email, :maximum => 255
  validates_format_of :notify_email, :with => EMAIL_REGEX
  validates_numericality_of :activation_price, :greater_than => 0.0, :unless => Proc.new {|a| a.franchisee.new_payment_model}
end

1 Ответ

0 голосов
/ 15 мая 2018

Проблема возникает в процессе проверки в a.franchisee.new_payment_model.

Я бы предположил, franchisee может быть nil. Я считаю, что это решит проблему:

validates_numericality_of
  :activation_price,
  :greater_than => 0.0,
  :unless => Proc.new { |a| a.franchisee.nil? || a.franchisee.new_payment_model}
end
...