Validation in ActiveInteraction not working

My code(for debug):

require 'active_interaction' class Sleep < ActiveInteraction::Base validate :validate_u def execute puts 1 1 end private def validate_u false end end res = Sleep.run res.result res.valid? res.errors.messages 

My result:

  • 2
  • 1
  • true
  • {}

Why is it? I was hoping the result would be:

  • nil
  • false
  • {there are message about faild becous invalid}

1 Answer

use

class Sleep < ActiveInteraction::Base validate :validate_u def execute puts 1 1 end private def validate_u errors.add(:base, :invalid) unless 'your validation condition' end end 

see doc:

record invalid when has errors in errors object

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like