如何垂直显示simple_form

时间:2014-08-10 16:26:56

标签: ruby-on-rails ruby ruby-on-rails-3 haml

= simple_form_for @session, :as => 'session', :url => session_path do |form|
  %form
    .form-group
      .form
        = form.input :email

      .form
        = form.input :password  

      .form-actions
        %button.btn.btn-primary{type: "submit"} Log in

上面的示例生成以下水平视图,其中输入字段位于标签右侧

*电子邮件[输入]

*密码[输入]

是否可以将它们垂直显示在彼此之上,因此标签位于输入字段之上?如何实现?

*电子邮件
[输入]

*密码

[输入]

3 个答案:

答案 0 :(得分:2)

= simple_form_for @session, :as => 'session', :url => session_path do |form|
  %form
    .form-group
      .form
         %div
           = form.label :email
           = form.email_field :email
         %div
           = form.label :password
           = form.password_field :password

答案 1 :(得分:1)

根据github页面: https://github.com/plataformatec/simple_form

<%= f.input :username, label: 'Your username please' %>

将标签设为块元素,而不是inline_label。

或者您可以单独指定标签和输入字段:

<%= f.label :username %>
<br/>
<%= f.input_field :username %>

答案 2 :(得分:0)

试试这个:

  %label Email*
  %div
    = form.input :email

  %label Password*
  %div
    = form.input :password