Bootstrap_form default scaffold view
This template is used to override default _form.html.erb view that is being generated by rails
Used 23 times
A
Amr Ahmed
Usage
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/VqqsJR"
Template Source
Review the code before running this template on your machine.
run 'bundle add bootstrap_form --version "~> 5.0"'
Dir.mkdir('lib/templates') unless File.exists?('lib/templates/erb/scaffold')
Dir.mkdir('lib/templates/erb') unless File.exists?('lib/templates/erb/scaffold/erb')
Dir.mkdir('lib/templates/erb/scaffold') unless File.exists?('lib/templates/erb/scaffold')
File.open("lib/templates/erb/scaffold/_form.html.erb", "w") {|f| f.write('<%%= bootstrap_form_with(model: @<%= singular_table_name %>, local: true) do |form| %>
<%% if <%= singular_table_name %>.errors.any? %>
<ul class="alert alert-danger list-unstyled">
<%% <%= singular_table_name %>.errors.each do |error| %>
<li><%%= error.full_message %></li>
<%% end %>
</ul>
<%% end %>
<% attributes.each do |attribute| -%>
<% if attribute.password_digest? -%>
<%%= form.label :password, style: "display: block" %>
<%%= form.password_field :password %>
<%%= form.password_field :password_confirmation %>
<% elsif attribute.attachments? -%>
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %>
<% elsif attribute.reference? -%>
<%%= f.collection_select :<%= attribute.column_name %>, <%= attribute.name.camelize %>.all, :id, :name, prompt: true %>
<% else -%>
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %>
<% end -%>
<% end -%>
<%%= form.primary %>
<%% end %>
') }