Uploading a file using the simple_form rails gem

Simple Form is a rails gem that takes a lot of stress out of dealing with forms in Rails. Knowing what field nomenclature handles file uploading should be simple but its not. It took a lot of screwing around and reading the documentation to figure it out.

Simple Form uses the Provided Rails Form helpers so, if you want to specify a file upload field in Rails, just do this

<%= simple_form_for @user, :html => {:multipart => true}  do |f| %>
    <%= f.file_format :photo, :label => 'Your avatar please' %>
 <% end %>
  • Nelson Khan

    Thank you for this. Can’t believe this isn’t an explicit example in the simple form docs.