jamesfwz
6/17/2014 - 10:35 AM

Simple Form.md

Gemfile

gem 'simple_form'

Installation

rails generate simple_form:install

# or with twitter bootstrap
rails generate simple_form:install --bootstrap

Set custom action for Form

= simple_form_for @participation, url: deal_join_path, method: :post do |f|
  = f.input :buyer_price, label: "Enter your desired price:"
  = f.button :submit, value: 'Join Deal', "data-disable-with" => "Submit.."

Using Simple Form without a modal

= simple_form_for :some_symbol do |f|
  = f.input :buyer_price, label: "Enter your desired price:"
  = f.button :submit, value: 'Join Deal', "data-disable-with" => "Submit.."

Styling radio buttons using Bootstrap

  • Simple form can't output the correct radio structure for bootstrap
# In a nested form
- prefix = "booking[guests_attributes][#{index}]"
.form-group
  = label_tag "#{prefix}[gender]", "Gender", class: 'required control-label col-md-4'
  .col-md-6
    .radio
      %label
        = radio_button_tag "#{prefix}[gender]", "Male", g.object.gender == "Male"
        Male
    .radio
      %label
        = radio_button_tag "#{prefix}[gender]", "Female", g.object.gender == "Female"
        Female