Skip to content

Instantly share code, notes, and snippets.

@kubakrzempek
Created April 21, 2016 11:56
Show Gist options
  • Save kubakrzempek/f6c15643b9adae7e3de27a6b946aee30 to your computer and use it in GitHub Desktop.
Save kubakrzempek/f6c15643b9adae7e3de27a6b946aee30 to your computer and use it in GitHub Desktop.
module MarketForms
Create = Dry::Validation.Form do
key(:code).required
key(:name).required
key(:countries_id).required
key(:description).required
key(:organization_id).required
key(:active).required
rule(code_organization_uniq: [:code, :organization_id]) do |code, organization_id|
unique?(code, organization_id)
end
configure do
option :market_repo, WheelsApp.instance["repositories.market"]
def unique?(organization_id, code)
market_repo
.markets
.by_org(organization_id)
.where(code: code)
.one
.blank?
end
end
end
end
@kubakrzempek
Copy link
Author

Works perfectly! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment