安装 `gem 'simple_form'`后,views都会有对应的小套路,这里总结一下。
一、`app/views/jobs/new.html.erb`
<h1>新建工作</h1>
<%= simple_form_for @job do |f| %> ***
<%= f.input :title, input_html: {class: "form-control"} %>
<%= f.input :description, input_html: {class: "form-control"} %>
<%= f.submit "Submit", class: "btn btn-primary", data: {disable_with: "Submiting..."} %> <% end %>
二、app/views/jobs/index.html.erb
<% @jobs.each do |job| %>
<%= link_to(job.title, job_path(job)) %>
<%= job.description %><%= link_to("Edit", edit_job_path(job), class: "btn btn-sm btn-default")%>
<%= link_to("Delete", job_path(job), class: "btn btn-sm btn-default",
method: :delete, data: { confirm: "Are you sure?" } )%>
三、app/views/admin/jobs/new.html.erb
Add a job
<%= simple_form_for [:admin, @job] do |f| %>
<%= f.input :title %><%= f.input :description %>
<%= f.submit "Submit" %>
<% end %>
四、app/views/posts/new.html.erb
<%=simple_form_for[@group,@post]do|f|%>
<%=f.input:content,input_html:{class:"form-control"}%><%=f.submit"Submit",disable_with:"Submiting...",class:"btn btn-primary"%>
<%end%>