File_field is not sticky in my Rails form

I have a pretty standard Rails form:

<div>
    <h1>Create a New Listing</h1>
    <%- form_for @listing, :html => {:multipart => true} do |f| -%>
                    <div><%= f.label :title, "Title:"%> <%= f.text_field :title %></div>
            <div>
                <%= f.label :image, "Image:" %> <%= f.file_field :image 
            </div>
            <div>
                <%= f.label :sound, "Sound Clip:"%> <%= f.file_field :sound %><br />
            </div>
        <div class="submit"><%= f.submit 'Post Listing' %></div>
    <%- end -%>
</div>

When a user selects a file, but the form fails for validation purposes, he should always reselect the file. It is not sticky. Any suggestion on how to fix this?

Thank!

+3
source share
1 answer

You cannot make the file field sticky, I think. Even if Rails provides the initial value, most browsers simply ignore it (or, otherwise, some smart-aleck can set the default file to /etc/passwd, and if you do not pay attention, then the following, that you know, your field is rooted.

, , , - , , , , , , .

:. , . , root. "" - , , - , Rails, , , .

, , ...

2: " " , " ". , , : innocent.txt CAPTCHA. , CAPTCHA , innocent.txt ~/.ssh/id_rsa. ( ), CAPTCHA submit. SSH-.

+6

Source: https://habr.com/ru/post/1749332/


All Articles