Created
August 21, 2020 06:22
-
-
Save mmhan/dcf4ee2f8295d8b2cc1cbf168ee7a2f5 to your computer and use it in GitHub Desktop.
Reform and Form Helper workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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