首页 > 代码库 > 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 %>
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%>
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 %>
简略版本
<%%= 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 %>
simple_form模板templates
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。