我有一个使用带有bootstrap的简单形式的表单:
= simple_form_for(@course) do |f|
= f.error_notification
.form-inputs
= f.input :name
= f.input :class_size
= f.simple_fields_for :lessons do |lesson|
= render 'courses/partial/lesson_fields', f: lesson
.links
= link_to_add_association 'Add Lesson', f, :lessons,
partial: 'courses/partial/lesson_fields', class: "btn btn-primary btn-xs"
.form-actions
= f.button :submit
lesson_fields.html.haml
.nested-fields
= f.input :date, as: :string, :input_html => { class: "datepicker" }
= f.input :location
= f.input :description
= link_to_remove_association "Remove Lesson", f, class: "btn btn-danger btn-xs"
如何将课程表格整理成一行?
答案 0 :(得分:0)
您是否遗漏了:html
部分?
= simple_form_for @object, html:{id:"<form_id>", class: "<you can define HTML classes here>"} do |f|
所以这里如果你想设置form-inline
类和simple_form_for
,那么你可以在html部分内设置它。
答案 1 :(得分:0)
尝试使用它:
= simple_form_for(@course, defaults: { input_html: { class: 'form-inline' } }) do |f|
= f.error_notification
.form-group
= f.input :name, input_html: { class: 'form-control' }
.form-group
= f.input :class_size, input_html: { class: 'form-control' }
.form-group
= f.simple_fields_for :lessons do |lesson|
= render 'courses/partial/lesson_fields', f: lesson
.links
= link_to_add_association 'Add Lesson', f, :lessons,
partial: 'courses/partial/lesson_fields', class: "btn btn-primary btn-xs"
.form-actions
= f.button :submit
我希望这对你有所帮助。