You are here: Home Solidarrow Ruby on Rails Solidarrow Cheatsheets

* Form Helpers Cheatsheet

Create forms, check boxes, radio buttons, select lists and more using Rails' built-in form helpers.

Multipart form

View

    <% form_for(@customer, :html => { :multipart => true }) do |f| %>
      <%= f.file_field :image_file %>
    <%= submit_tag %>
    <% end %>

Model

    class Customer < ActiveRecord::Base
      def image_file      =(uploaded_data)
        self.filename     = uploaded_data.original_filename
        self.image_data   = uploaded_data.read
        self.size         = uploaded_data.size
        self.content_type = uploaded_data.content_type  
      end
    end



 

 

> RELATED ARTICLE

* Quickly debugging form helpers

Sometimes you want to quickly see the output of helper methods, and constantly clicking refresh in your browser then viewing the page source can be tiresome. Instead, use the Rails console to check helpers are doing what you want them to. > More