在标签标签中嵌套Ruby on Rails HAML复选框

时间:2012-03-19 17:06:23

标签: ruby-on-rails ruby haml

我有以下代码不起作用:

= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :class => "well" }) do |f|

= f.label :email
= f.email_field :email

= f.label :password
= f.password_field :password
- if devise_mapping.rememberable?
 %p
  = f.label :remember_me, :class => "checkbox" 
    = f.check_box :remember_me, :class => "checkbox"

  %div= f.submit "Einloggen"
= render :partial => "devise/shared/links"

它只能以这种方式工作,但我需要它在一行而不是在wto:

%p
  = f.label :remember_me, :class => "checkbox" 
  = f.check_box :remember_me, :class => "checkbox"

请帮忙!我现在真的很鄙视。我只想在bootrap表单的标签中嵌套复选框。我搜索了google和stackoverflow但没有找到任何内容

更新:

我现在解决了这个问题:

- if devise_mapping.rememberable?
%p
  %label.checkbox{ :for => "remember_me" }
    = f.check_box :remember_me, :class => "checkbox"
    Remember 

2 个答案:

答案 0 :(得分:12)

怎么样:

%p
  = f.label :remember_me, :class => "checkbox" do
    = f.check_box :remember_me, :class => "checkbox"

答案 1 :(得分:0)

使用:

%p #{f.label :remember_me, :class => :checkbox} : #{f.check_box :remember_me, :class => :checkbox}