I installed the story model with an image application processed by Paperclip, which looks like this:
class Story < ActiveRecord::Base has_attached_file :image
When I fill out my story, it looks like this:
<%= form_for @story, html: { multipart: true } do |f| %> <% if @story.errors.any? %> <div id="error-explanation"> <ul> <% @story.errors.full_messages.each do |msg| %> <li class="error-mess">Error: <%= msg.downcase %></li> <% end %> </ul> </div> <% end %> <%= f.text_field :title %></td> <%= f.file_field :image %> <%= f.submit t('.send') %> <% end %>
If the check is too long for story.title, the form displays correctly again with the correct error message and an invalid header, but file_field now empty and I have to click it again to re-select the file I want to upload .
And this is what my story_controller.rb looks like:
def create @story = @current_user.stories.new(params[:story]) if @story.save redirect_to thanks_path else
How can I avoid the user re-selecting the file to download after a validation error?
ruby-on-rails file-upload paperclip
Darme
source share