繁体   English   中英

在input和= f.input之间使用simple_form遇到麻烦

[英]Trouble using simple_form between input and =f.input

在此处输入图片说明

这是下面苗条的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'

您可以使用install生成器获取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放在新行中,这将分隔跨度和输入。 请参阅此答案以了解更多详细信息使用simple_form附加/添加引导程序图标

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM