Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with dry-validation 1.3 #504

Closed
marvintrejoxi opened this issue Nov 28, 2019 · 5 comments
Closed

Error with dry-validation 1.3 #504

marvintrejoxi opened this issue Nov 28, 2019 · 5 comments

Comments

@marvintrejoxi
Copy link

I have been getting this error with dry-validation in my contract

undefined method `required' for #<Class:0x00007fa7846c9ca0>\nDid you mean?  require

this is my contract:

class BusinessLine::Contract::Create < Reform::Form
      property :name
      property :code
      property :status

      validation name: :default do
        required(:name).filled
      end

      collection :business_line_sections, populator: :business_line_sections! do
        property :section_id
      end

      collection :services, populator: :services! do
        property :name
        property :code
        property :price
        property :status

        collection :additional_services, populator: :additional_services! do
          property :name
          property :code
          property :price
          property :status
        end

        def additional_services!(fragment:, **)
          additional_services.append(::AdditionalService.new)
        end
      end

      def business_line_sections!(fragment:, **)
        business_line_sections.append(::BusinessLineSection.new)
      end

      def services!(fragment:, **)
        services.append(::Service.new)
      end
    end

and Im using those gems:

gem 'trailblazer', '2.1.0'
gem 'trailblazer-rails', '2.1.7'
gem 'trailblazer-operation', '0.6.0'
gem 'reform', '2.3.0.rc2'
gem 'reform-rails', '0.2.0.rc3'
gem 'dry-validation', '1.3.1'
gem 'dry-monads', '1.3.1'

any idea why dry validation doesn't work correctly with reform gem in that version?

@seuros
Copy link
Member

seuros commented Nov 28, 2019

@marvintrejoxi , the validation syntax you have is wrong, check out the documentation of Dry.

Also you need to add feature Dry in the contract.

@seuros seuros closed this as completed Nov 28, 2019
@marvintrejoxi
Copy link
Author

@seuros i have that in one initializer

/conf/initializer/reform.rb
require 'reform/form/dry'

Rails.application.config.reform.validations = :dry

Reform::Form.class_eval do
  feature Reform::Form::Dry
end

however, I always get the same error

@seuros
Copy link
Member

seuros commented Nov 28, 2019

https://dry-rb.org/gems/dry-validation/1.3/

The block validation is the Dry::Validation::Contract

@marvintrejoxi
Copy link
Author

@seuros can you give an example of a contract with validations? because, i dont understand you :(

@seuros
Copy link
Member

seuros commented Nov 28, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants