码迷,mamicode.com
首页 > 其他好文 > 详细

simple_form模板templates

时间:2016-11-25 17:42:51      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:inline   htm   ide   com   技术   checkbox   ble   sub   ati   

通过新建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

标签:inline   htm   ide   com   技术   checkbox   ble   sub   ati   

原文地址:http://www.cnblogs.com/tabCtrlShift/p/6102047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!