"a": {}
, and "b": {"string"}
?property :a
i received : undefined method 'a=' for ...property :a do
property :e
end
Rendering_nil = true
not help...Hello, guys. Could you please help me with Reform::Form.
class SearchForm < Reform::Form
feature Coercion
property :lat, virtual: true, type: Types::Nominal::Float
property :lon, virtual: true, type: Types::Nominal::Float
property :query_type, virtual: true, type: ::Types::Nominal::String
property :q, virtual: true, type: Types::Nominal::String
property :radius, virtual: true, type: Types::Nominal::Float, default: 200
end
I set up types for properties in Form with feature Coercion. As I read from reform documentation these types are valid only during validation.
How to apply types to form fields to be sure that I can use float values (not strings by default) as values of properties.
Anybody have good solutions for handling polymorphic collections with Reform?
I have a Resource model which belongs_to: source, polymorphic: true
I have something like:
class Form < Reform::Form
collection(
:resources,
populate_if_empty: Resource,
) do
property :source, form: Source::Form
end
end
I've tried a sad hack that strips my definitions in the source form:
module Source
module Form
def self.new(model)
model.class::Create::Form.new(model)
end
def self.definitions()
[]
end
end
end
But this leads to some issues with validation and prepopulating the form after errors (I lose objects that do not have a hash). Anybody have any tips for how they handle this? I'm thinking of just managing the children and errors manually myself but wanted to ask anyways
Hi, we have a Problem with Trailblazer and Representer. I became the following Error: NoMethodError - undefined method 'new' for Patients::BillingAddress:Module:
by update a Record in my Database.
My representer Class:
class Patients::PatientInsurance::Representer::In::Default < Webapp::Representer
resource :patient_insurances
attributes do
property :valid_since
end
has_one :billing_address, class: BillingAddress, decorator: Patients::BillingAddress::Representer::In::Default
end
Does anyone have a solution for the problem or a tip for me?
Hi guys, suppose that I have a JSON like this:
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "kk2bw5ojx476"
}
},
"id": "3n2wPdC9GGi2QCdnrW4Ifz",
"type": "Entry",
"createdAt": "2020-04-21T13:37:24.567Z",
"updatedAt": "2020-05-06T15:11:35.360Z",
"environment": {
"sys": {
"id": "master",
"type": "Link",
"linkType": "Environment"
}
},
"revision": 2,
"contentType": {
"sys": {
"type": "Link",
"linkType": "ContentType",
"id": "footerSectionItem"
}
},
"locale": "en-US"
},
"fields": {
"title": "Germany",
"url": "https://marleyspoon.de"
}
}
I've defined my representer this way:
class EntryNormalizer < Representable::Decorator
include Representable::JSON
nested :sys do
nested :contentType do
nested :sys do
nested :id, as: :type
end
end
end
end
But it doesn't work and instead raises an error that says from_hash is not defined. Do you know how can I fetch a nested property with depth more than 1?
class Payment < ApplicationRecord
belongs_to :invoice
end
module V1::Payment::Contract
class Form < Reform::Form
property :invoice_id
end
end
@form = V1::Payment::Contract::Form.new(Payment.new)
@form.validate({invoice_id: 1888888888888})
Expectation: @form.errors if invoice by this id doesn't exist
class NewForm < Reform::Form
property :invoice_id
validates :invoice_id, presence: true
end
trb_demo[dev]:015 >> new_form = NewForm.new(Payment.new)
trb_demo[dev]:016 >> new_form.validate({})
=> false
trb_demo[dev]:017 >> new_form.validate({invoice_id: 1})
=> true
trb_demo[dev]:018 >> new_form.validate({invoice_id: nil})
=> false
collection :sources, form: SourceForm
but my guess didn't work)
field: :hash
but it doesn't seem to like combining collections and the form:
option
# form object
class GroupForm < Reform::Form
include Reform::Form::ActiveModel
include Reform::Form::ActiveModel::FormBuilderMethods
# doesn't seem to work
# because there is no to_email on the active model Group object
# was wondering how this is handled in Reform?
collection :to_emails
end
# controller
@group = Group.new(project: @project)
@form = GroupForm.new(@group)
Hi everyone! Am new to trailblazer. I have a rails 6 app and was able to create an operation and its form. Now I want to add validation and, unfortunately it is not working. Am getting this error:
NoMethodError:
undefined method `required' for #<Class:0x00007fa75583f8c0>
Did you mean? require
Am trying to use reform with dry-validation
. This is my setup:
# Gemfile
gem 'rails', '~> 6.1'
gem 'trailblazer-rails', '~> 2.1.7'
gem 'reform', '~> 2.3.3'
gem 'dry-validation'
# app/concepts/subscriptions/contract/create.rb
require 'reform/form/dry'
module Subscriptions::Contract
class Create < Reform::Form
feature Reform::Form::Dry
property :subscription_details
property :user
validation :default do
required(:subscription_details).filled # This is where the error is raised
end
end
end
# app/concepts/subscriptions/operation/create.rb
module Subscriptions::Operation
class Create < Trailblazer::Operation
step Model(WebPushSubscription, :new)
step Contract::Build(constant: Subscriptions::Contract::Create)
step Contract::Validate()
step Contract::Persist()
end
end