Skip to content

Instantly share code, notes, and snippets.

@ivan22
Created May 17, 2014 03:16
Show Gist options
  • Select an option

  • Save ivan22/a9a95db02880653c31b7 to your computer and use it in GitHub Desktop.

Select an option

Save ivan22/a9a95db02880653c31b7 to your computer and use it in GitHub Desktop.
Simple Form

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment