Closed Titinux closed 7 years ago
Hm, you're right, the value
reader shouldn't be called at all if the :value
key is present.
The idea behind that is to allow not calling anything when rendering a form, e.g. for "virtual" fields.
Thanks for your bug reports @Titinux, they are very understandable and excellent. :rocket:
:point_up: @emaglio @fran-worley @trailblazer/website
Should we refrain from calling the value reader on the model if the key :value
is present in the options hash?
I have tried to recreate the issue in gemgem-sinatra
but as per @Titinux expectation when value is set to nil
I have value: ""
:
some = nil
= f.input(:title, value: some).to_s
<input value="" name="title" id="title" class="form-control" type="text">
I'm missing something maybe...
@emaglio Does title a function or a var defined in your example ?
@Titinux It's a property of a contract: https://github.com/apotonick/gemgem-sinatra/blob/formular-slim-bootstrap3/concepts/post/operation/create.rb#L6
I usually have undefined method
when you try to use something not defined in your model/contract
@Titinux is right, if an option is set to nil it attempts to call the default method which in this case, was the reader value. I agree that this doesn't make sense as you'd assume that in passing an option, that option would be respected regardless of its value.
I've now changed this & included a couple of test cases to prove it.
I'm using formular master branch
When value is set to nil, the element try to call a method named after the first parameter. Is this the right behaviour ? I was expecting a tag with value attribute set to an empty string.
=>
<input value="my_value" name="foo" id="foo" type="text">
=>
undefined method 'foo'