Simpleform需要一些配置才能很好地與bootstrap配合使用。
創建初始化程序和配置simpleform與引導工作:
# File here config/initializers/simple_form_bootstrap.rb
SimpleForm.setup do |config|
config.wrappers :vertical_input_group, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.use :label, class: 'control-label'
b.wrapper tag: 'div' do |ba|
ba.wrapper tag: 'div', class: 'input-group col-sm-12' do |append|
append.use :input, class: 'form-control'
end
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
config.wrappers :horizontal_input_group, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.use :label, class: 'col-sm-3 control-label'
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
ba.wrapper tag: 'div', class: 'input-group col-sm-12' do |append|
append.use :input, class: 'form-control'
end
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
end
更多信息可以在這裏找到:https://github.com/plataformatec/simple_form/wiki/How-to-use-Bootstrap-3-input-group-in-Simple-Form
但我不會在用戶 – adolzi
中調用這個simple_form您不必在用戶控制器中調用simple_form,它的視圖就足夠了.Juts在您使用的控制器中調用@user = User.new的關係。 –
和@user在其視圖中 –