【问题标题】:Simple_form how to make accept terms checkbox inlineSimple_form 如何使接受条款复选框内联
【发布时间】:2012-10-14 18:25:09
【问题描述】:
<p><%= f.input :terms, :as => :boolean, :label => false, :boolean_style => :inline %> 
Accept <%= link_to "Terms of use", terms_path,:remote => true %> 
and <%=link_to "privacy Policy", privacy_path, :remote => true%></p>

它最终看起来像这样

将它们排列在同一条线上的最佳方式是什么。

【问题讨论】:

    标签: html css ruby-on-rails twitter-bootstrap simple-form


    【解决方案1】:

    这是一个相当简单的方法:

    <%= content_for(:the_links) do %>
        Accept <%= link_to "Terms of use", terms_path,:remote => true %> 
        and <%=link_to "privacy Policy", privacy_path, :remote => true%>
    <% end %>
    
    <%= simple_form_for @user do |f| %>
      <%= f.input :email %>
      <%= f.input :password %>
      <%= f.input :terms, :as => :boolean, :label => content_for(:the_links)%> 
    <% end%>
    

    【讨论】:

    • 很好地使用 content_for 块:)
    • 嘿,这是content_for 的绝妙技巧。非常有用。
    • 这仅在我将 :label 更改为 :inline_label 时对我有用
    【解决方案2】:

    确保复选框和文本足够小以适合容器内的一行,然后设置display: inline;float:left;

    【讨论】:

    • display: inline 不起作用,float left 起作用,但看起来很奇怪,因为我的表单居中。
    【解决方案3】:

    尝试像这样使用wrapper_html

    <p>
      <%= f.input :terms, 
                :as => :boolean, 
                :label => false, 
                :boolean_style => :inline,     
                :wrapper_html => { :style => 'display: inline' } 
      %> 
      Accept <%= link_to "Terms of use", terms_path,:remote => true %> 
      and <%=link_to "privacy Policy", privacy_path, :remote => true%>
    </p>
    

    【讨论】:

      猜你喜欢
      • 2011-07-26
      • 2021-04-03
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多