-
Notifications
You must be signed in to change notification settings - Fork 183
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
exception raised when nested property is nil #67
Comments
+1 I just ran into this issue as well for my has_one association. |
This is a common misunderstanding of how Reform and representable work with models. This discussion gives some insight. Basically, it's up to you to setup your model before passing it to the form. However, since this seems to be pretty inconvenient, representable will come up with a solution. |
@apotonick, I too have this issue. The problem for me is that with the example above, it is completely valid to have a |
Let's say reform would allow - if @form.artist
= render 'form/artist' or how do you guys deal with those edge-cases? |
Fixed in master: 0dbbe0c#diff-55fdd0dd35969b77c2c643869ac9d25eR182 Please test and also I need some feedback on my last comment. |
@apotonick, thanks for this, I will test it out. However, as you say, I suppose importantly we need to consider what will happen with BTW. On a separate note, I originally started using another form gem, but quickly switched across to I'll issue a PR now to cover expected behaviour. I don't claim this is right, it's just what I think I would need. |
I have some thoughts on form objects not backed by any model: I call this a "contract" or "Validator" in an upcoming pattern collection. Reform can handle that out-of-the-box. What's your intended workflow with such a form object? |
Here's an example where I am using a custom wrapped form object. Does that make sense? How would Reform handle that out of the box? |
You'd just do Maybe this is a good thing to document. And the reason this might look clumsy is because Reform explicitely tries not to expose 721 public methods but a clean set of as-stateless-as-possible public concerns. |
Mmm, as you will see in the tests I provided, simply providing an |
The following code for me is triggering a big stacktrace with error
NoMethodError: undefined method
name' for nil:NilClass`One way around this is to override the
#initialize
and ensure that the nested property (model.artist) exists, but I think that might be too brittle. I have a couple of ideas on how to possibly fix this:#initialize
could call a newprepare_model
method which subclasses of Reform::Form could override. Not a great deal better than overriding#initialize
though.property
method could support a:builder
option that takes a block, or symbol containing a method name to invoke on the model (i.e.:build_artist
in ahas_one/belongs_to
ActiveRecord relationship).What are your thoughts?
The text was updated successfully, but these errors were encountered: