Skip to content

Instantly share code, notes, and snippets.

@mmhan
Created August 21, 2020 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmhan/dcf4ee2f8295d8b2cc1cbf168ee7a2f5 to your computer and use it in GitHub Desktop.
Save mmhan/dcf4ee2f8295d8b2cc1cbf168ee7a2f5 to your computer and use it in GitHub Desktop.
Reform and Form Helper workaround
# concepts/thing/contract/contract.rb
require 'disposable/twin/property/hash'
module Thing::Contract
class Contract < Reform::Form
include Disposable::Twin::Property::Hash
property :data, field: :hash do
property :foo_bar
end
end
end
# views/things/_form.html.erb
# <%= f.simple_fields_for :data do %>
# <%= f.input :foo_bar %>
# <% end %>
# f.simple_fields_for will raise error, method `persisted?` not found for Hash:{}
## Work around
# concepts/thing/contract/contract.rb
require 'disposable/twin/property/hash'
module Thing::Contract
class Contract < Reform::Form
include Disposable::Twin::Property::Hash
property :data, field: :hash do
# Add this
def persisted?
false
end
property :foo_bar
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment