High-level rule using many fields


#1

Hello!

I need high-level rule that accepts additional fields to validate form
This solution is not working time_occupied? predicate arity is invalid

configure do
  def time_occupied?(start_from, end_at, id)
    //
  end
end
rule(time_occupied_rule: [:id, :start_from, :end_at]) do |id, start_from, end_at|
  id.time_occupied?(start_from, end_at)
end

Is there any solution in this case?

version: 0.10.7


#2

@niewicz you can do it with a custom validation block

configure do
  def time_occupied?(id, start_from, end_at)
    //
  end
end

validate(time_occupied_rule: [:id, :start_from, :end_at]) do |id, start_from, end_at|
  time_occupied?(id, start_from, end_at)
end

#3

Thank you! it solved my issue :slight_smile: