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 %>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>