heartcombo / simple_form

Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
http://blog.plataformatec.com.br/tag/simple_form
MIT License
8.22k stars 1.32k forks source link

Incorrectly mapping a varchar column to a file input #1733

Closed andyrue closed 2 years ago

andyrue commented 3 years ago

Environment

Current behavior

I have a varchar column field named "poa" inside a table named "poas". When I use f.input on that field it is being wrapped in a div with a "file" class and has an input type='file'. I have recently upgraded from Rails 4.2 and Simple_Form 4.0 and this wasn't an issue before. I'm not having this problem with any other varchar field. The only things special about this column is it is named the same as the model, and there is also a poa_attachment column that is used for a carrierwave uploader. Not sure if there is some sort of magic happening in the background that is getting some wires crossed or something.

<%= f.input :poa, label: 'POA', wrapper_html: { class: 'columns medium-6' } %>

This is the resulting html

<div class="input file optional record_poa_poa valid columns medium-6">
    <label class="file optional" for="record_poa_attributes_poa">POA</label>
    <input class="file optional" type="file" name="record[poa_attributes][poa]" id="record_poa_attributes_poa">
</div>

Expected behavior

I expect the field to be treated as a text input. I can get around it by adding as: :string to the field, but I shouldn't have to do that.

nashby commented 2 years ago

Hey! Yeah, that's because you have poa_attachment column in your model. You can check how SimpleForm detects file inputs here https://github.com/heartcombo/simple_form/blob/86429bceb950096df3c29616f31bd5a5ce706c06/lib/simple_form/form_builder.rb#L592. So for your case you can use as: :string to avoid it. Unfortunately it's hard to make it work properly for all the case.