Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails Essentials: simple_form

Rails Essentials: simple_form

Houston Ruby Brigade appetizer to simple_form (rails form DSL)

Jesse Wolgamott

October 10, 2012

Transcript

10 slides
  1. rails g scaffold post title body publish_on:date featured:boolean Why is

    this needed? <%= simple_form_for(@post) do |f| %> <%= f.error_notification %> <div class="form-inputs"> <%= f.input :title %> <%= f.input :body %> <%= f.input :publish_on %> <%= f.input :featured %> </div> <div class="form-actions"> <%= f.button :submit %> </div> <% end %>
  2. As Compared to <%= form_for(@post) do |f| %> <% if

    @post.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> <ul> <% @post.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :title %><br /> <%= f.text_field :title %> </div> <div class="field"> <%= f.label :body %><br /> <%= f.text_field :body %> </div> <div class="field"> <%= f.label :publish_on %><br /> <%= f.date_select :publish_on %> </div> <div class="field"> <%= f.label :featured %><br /> <%= f.check_box :featured %> </div> <div class="actions"> <%= f.submit %> </div> <% end %>
  3. Let’s see that again <%= simple_form_for(@post) do |f| %> <%=

    f.error_notification %> <div class="form-inputs"> <%= f.input :title %> <%= f.input :body %> <%= f.input :publish_on %> <%= f.input :featured %> </div> <div class="form-actions"> <%= f.button :submit %> </div> <% end %>
  4. 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
  5. 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
  6. Bootstrap Integration Yes, it does this nicely And there’s a

    bootstrap picker. demo (github.com/houstonruby/rails_essentials/simple_form

More Decks by Jesse Wolgamott

Other Decks in Technology