0

enter image description here

  validates_presence_of :job, if: Proc.new { |data| data.executed_at? }

I have been tinkering with fixing this issue and it continually fails. If I switch to the recommended proc it chokes on:

enter image description here

What is the best way to process this and pass the cops?

In case others land here, the final syntax was:

validates_presence_of :job, if: proc { executed_at? }
Chris Hough
  • 3,389
  • 3
  • 41
  • 80

1 Answers1

1

You've simply fixed one issue to be confronted with another. Time to fix that one.

validates_presence_of :job, if: :executed_at?
steel
  • 11,883
  • 7
  • 72
  • 109
  • in trying that I get the error "ArgumentError: tried to create Proc object without a block" – Chris Hough Mar 05 '16 at 02:45
  • Right. On the flip side, I think we can just pass the method name as a symbol. http://guides.rubyonrails.org/active_record_validations.html#conditional-validation I've updated my answer. – steel Mar 05 '16 at 02:52
  • with @Carpetsmoker's help it works with validates_presence_of :job, if: proc { executed_at? } but I am waiting the posted answer so I can give credit. if you want it first go for it, you both were helping me – Chris Hough Mar 05 '16 at 02:53
  • I think that's more than than you need. You don't really need a proc in this case. I suspect either `if: Proc.new(&:executed_at?)` or `proc(&:executed_at?)` would work, too, but I'm not sure. – steel Mar 05 '16 at 02:54
  • 1
    the comment he posted fixed the issue, and I updated it so others do not post on this topic. thank you again for the help – Chris Hough Mar 05 '16 at 02:55