如何在simple_form标签旁边添加范围

时间:2012-08-18 23:17:26

标签: ruby-on-rails simple-form

我正在尝试添加一个包含标签旁边的字符计数器的范围。标签是使用simple_form生成的,我似乎只能将跨度放在字段的上方或下方。我试过的代码段如下:

<%= simple_form_for(@message, :html => {:class => 'form-vertical' }) do |f| %>
<div class="inputs">
<%= f.input :to_user_id, :required => true, :as=> :hidden %><span id="counter">160</span>
<%= f.input :content, :required => true, :input_html=> { :class=> "field-message span6", :placeholder=> "your message goes here, keep it short, 140 characters short..." } %>
</div>

1 个答案:

答案 0 :(得分:2)

表单构建器将使输入字段自包含,因此一种方法是让div'输入'左浮动,然后将“counter”左浮动放在它旁边。

styles.css的

input { 
  clear: both;
  float: left; 
  width: 150px; 
}
#counter { float: left; width: 150px; }

form.html.erb

...
<%= f.input :to_user_id, :required => true, :as=> :hidden %>
<div id="counter">160</div>
<%= f.input :content, :required => true, ....