刘华佼的全栈学习记录

如何使用SimpleForm简化

| Comments

目标:

使用SimpleForm简化套用bootstrap的代码

步骤一:安装“simple_form” gem

Gemfile里新增:gem ‘simple_form’

步骤二:terminal中运行bundle install

步骤三:安装simple_form对bootstrap的设定

rails generate simple_form:install —bootstrap

步骤四:重开server

ctrl+c终止,rails s重开

步骤五:修改_form.html.erb

<%= simple_form_for @group do |f| %>
  <div class="form-group">
    <%= f.input :title, input_html: { class: "form-control"} %>
    <%= f.input :description, input_html: { class: "form-control"} %>
  </div>
  <%= f.submit "Submit", class: "btn btn-primary", data: { disable_with: "Submiting..." } %>
<% end %>

Comments

comments powered by Disqus