Conversation
|
got two tests failing but they also fail before my change: and |
|
👍 |
|
I would rather implement that as a module and then make people include it, e.g. |
|
Make sense ;). However have you seen the related discussion on gitter : I think it make sense to also add such a feature @ reform level directly, in which case the new reform-rails Modelless module could be called automatically. |
|
Oh interesting, I did not see that discussion! 👍 |
|
changed it to a separate module. Is this what you had in mind? I didn't completely split it from the active_model code as I didn't dive into the meaning/pupose of all the code in there, so you have to include both ActiveModel & NotPersisted (see related test). I guess it could be possible to split it more when using dry-validation, however the used Form builder could still request several active_model API calls... Perhaps a feature 'NotPersisted' can be added to reform which will automatically
|
|
Closing and reopening to trigger travis build |
|
@fran-worley as a Repo Member you can start a rebuild via the Travis UI |
|
@timoschilling that only works if a build existed in the first place. I setup travis after these PRs were open and this seemed to be the only way to trigger a build. |
|
ah ok, never mind |
In some cases reform is just used for coercion & validation without any persistence done.
In these cases it was advised to use nil as reform model & to mark all properties as virtual.
this works fine, however fails as .persisted? is called on nil upon rendering in actionpack-3.2.22.2/lib/action_view/helpers/form_helper.rb:388
...
as = options[:as]
action, method = object.respond_to?(:persisted?) && object.persisted? ? [:edit, :put] : [:new, :post]
options[:html].reverse_merge!(
:class => as ? "#{action}_#{as}" : dom_class(object, action),
:id => as ? "#{action}_#{as}" : [options[:namespace], dom_id(object, action)].compact.join("_").presence,
:method => method
)
...
|
What model/ class are you providing the form on initialisation? I'd like to find a more elegant way of doing this if possible, but would need to know a little more about how you would intend to use it. Can you provide an example form ? |
|
@fran-worley The goal was to use the validation and coercion logic from Reform, but not the persistence functionality. Perhaps in addition a representer could be inferred from the Reform contract The cases I encountered:
The last case is now solved using dry-validation instead of a Reform contract. The first case is currently solved using an OpenStruct as model. Example of Reform of first case : http://pastebin.com/Fjz3SLwq. |
|
Approach I'm using: |

In some cases reform is just used for coercion & validation without any persistence done.
In these cases it was advised to use nil as reform model & to mark all properties as virtual.
this works fine, however fails as .persisted? is called on nil upon rendering in actionpack-3.2.22.2/lib/action_view/helpers/form_helper.rb:388