这是下面简洁的simple_form表单的截图。这表明正确。但这给了我类型nil错误。
= simple_form_for :identity, :url => '/auth/identity/register' do |f|
h2 Create New Account
.form-actions
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
input type="text", label:false, :class => "inline"
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
input type="text" id="" name="" f:email
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
input type="text" id="" name="" f:password
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
input type="text" id="" name="" f:password_confirmation
.control-group
.controls
= f.button :submit, :class => 'btn-primary'
这是以下代码的屏幕截图。这样可以正常工作(不会给出nil类型错误。因为它需要模型字段。)但是外观被分解了。
= simple_form_for :identity, :url => '/auth/identity/register' do |f|
h2 Create New Account
.form-actions
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
=f.input :name, label:false
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
= f.input :email, label:false
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
= f.input :password, label:false
.control-group
.controls
.input-prepend
span.add-on
i.icon-user
= f.input :password_confirmation, label:false
.control-group
.controls
= f.button :submit, :class => 'btn-primary'
答案 0 :(得分:1)
您可以使用install generator
获取simple_form以生成twitter引导程序表单rails generate simple_form:install --bootstrap
您不必这样做,但它会使您的表单更简单!请参阅文档https://github.com/plataformatec/simple_form
然后,为了回答您的实际问题,您可以像这样添加用户图标
= f.input :email, :wrapper => :append do
= f.input_field :email
%span.add-on>
%i.icon-user
>在加载项停止haml放入一个新的行,这将分隔跨度和输入。有关详细信息Append/prepend bootstrap icons with simple_form
,请参阅此答案