简体   繁体   English

我如何摆脱将每个输入都包装在simple_form中的div?

[英]How do I get rid of the div that wraps every input in a simple_form?

This input: 此输入:

<%= f.input :keywords, label: false, :input_html => {:class => "span8"}, :placeholder => "Park Slope, Prospect Heights, Fort Green..." %>

Produces this: 产生这个:

<div class="control-group string optional">
  <div class="controls">
     <input class="string optional span8" id="search_keywords" name="search[keywords]" placeholder="Park Slope, Prospect Heights, Fort Green..." size="50" type="text" />
  </div>
</div>

How do I just generate the input alone without the divs around it? 如何仅在没有div的情况下仅生成input

Thanks. 谢谢。

Well do something like this pass a params wrapper: false like this 好吧,这样的事情通过一个params wrapper: false就像这样

<%= f.input :keywords, 
            label: false,
            wrapper: false,
            input_html: { class: 'span8' }, 
            placeholder: 'Park Slope, Prospect Heights, Fort Green...' %>

And See it would work 并看到它会工作

Hope this help 希望这个帮助

So it seems the best way to do this is to use f.input_field . 因此,似乎最好的方法是使用f.input_field

The docs for Simple_Form don't quite spell it out, but you can view the actual API docs here . Simple_Form的文档不太清楚,但是您可以在此处查看实际的API文档

From the docs: 从文档:

simple_form_for @user do |f|
  f.input_field :name
end

Will Produce: 将产生:

<input class="string required" id="user_name" maxlength="100"
   name="user[name]" size="100" type="text" value="Carlos" />

使用常规的text_field

<%= f.text_field :keywords, :class => "string optional span8", :placeholder => "Park Slope, Prospect Heights, Fort Green..." %>

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

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