Slide 1

Slide 1 text

SIMPLE FORM Rails Essentials: @jwo

Slide 2

Slide 2 text

gem “simple_form” bundle rails g simple_form:install By Platformatec (same cats as Devise)

Slide 3

Slide 3 text

rails g scaffold post title body publish_on:date featured:boolean Why is this needed? <%= simple_form_for(@post) do |f| %> <%= f.error_notification %>
<%= f.input :title %> <%= f.input :body %> <%= f.input :publish_on %> <%= f.input :featured %>
<%= f.button :submit %>
<% end %>

Slide 4

Slide 4 text

As Compared to <%= form_for(@post) do |f| %> <% if @post.errors.any? %>

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

    <% @post.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :body %>
<%= f.text_field :body %>
<%= f.label :publish_on %>
<%= f.date_select :publish_on %>
<%= f.label :featured %>
<%= f.check_box :featured %>
<%= f.submit %>
<% end %>

Slide 5

Slide 5 text

Let’s see that again <%= simple_form_for(@post) do |f| %> <%= f.error_notification %>
<%= f.input :title %> <%= f.input :body %> <%= f.input :publish_on %> <%= f.input :featured %>
<%= f.button :submit %>
<% end %>

Slide 6

Slide 6 text

It’s Just a Wrapper All form_helpers in Rails apply select, collection_select, date_select You can pass to the HTML of the form or the input

Slide 7

Slide 7 text

Why over Formtastic? Formtastic had a strong opinion on form markup created You can define what markup to use with your CSS Twitter Bootstrap, Zurb Foundation, ALL CAN BE YOURS

Slide 8

Slide 8 text

GUESS WHAT

Slide 9

Slide 9 text

Associations has many throughs are now SIMPLE. f.association :categories, as: :check_boxes

Slide 10

Slide 10 text

Bootstrap Integration Yes, it does this nicely And there’s a bootstrap picker. demo (github.com/houstonruby/rails_essentials/simple_form