首页 > 代码库 > simple_form模板templates

simple_form模板templates

通过新建lib/templates/erb/scaffold/_form.html.erb,来重写scaffold生成view下_form.html.erb的默认模板

Bootstrap: Basic Form:

技术分享
<%%= simple_form_for(@<%= singular_table_name %>) do |f|%>
  <%%= f.error_notification%>
  <div class="col-md-6">
    <div class="form-inputs">
  <%- attributes.each do |attribute| -%>
        <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>%>
  <%- end -%>
    </div>
  </div>

  <div class="form-actions">
    <%%= f.button :submit %>
  </div>
<%% end %>
View Code

 Simple Form: Inline Form

技术分享
<%%= simple_form_for @aab, wrapper: :inline_form, html: { class: form-inline } do |f| %>
  <%%= f.error_notification %>

  <%- attributes.each do |attribute| -%>
    <%%= f.<%= attribute.reference? ? :association : :input%>:<%= attribute.name%>, placeholder: Enter <%= attribute.name%>%>
  <%- end -%>

  <%%=f.button :submit %>
<%% end%>
View Code

Simple Form: Horizontal Form

技术分享
<%%= simple_form_for @<%= singular_table_name%>, as: user_horizontal, html: { class: form-horizontal },
  wrapper: :horizontal_form,
  wrapper_mappings: {
    check_boxes: :horizontal_radio_and_checkboxes,
    radio_buttons: :horizontal_radio_and_checkboxes,
    file: :horizontal_file_input,
    boolean: :horizontal_boolean
  } do |f| %>
  <%%= f.error_notification %>
  <div class="col-md-6">
    <div class="form-inputs">
    <%- attributes.each do |attribute| -%>
    <%%= f.<%= attribute.reference? ? :association : :input%>:<%= attribute.name%>, placeholder: <%= attribute.name%>%>
  <%- end -%>

  <%%= f.input :file, as: :file %>

  <%%= f.input :sex, as: :radio_buttons,
    collection: ["Male", "Female"] %>
    </div>
  </div>

  <%%= f.button :submit %>
<%% end %>
View Code

简略版本

技术分享
<%%= simple_form_for @<%= singular_table_name%>, as: user_horizontal, html: { class: form-horizontal },
  wrapper: :horizontal_form do |f| %>
  <%%= f.error_notification %>
  <div class="col-md-6">
    <div class="form-inputs">
    <%- attributes.each do |attribute| -%>
    <%%= f.<%= attribute.reference? ? :association : :input%>:<%= attribute.name%>, placeholder: <%= attribute.name%>%>
  <%- end -%>
    </div>
  </div>

  <%%= f.button :submit %>
<%% end %>
View Code

 

simple_form模板templates