Adding controls inline with simple_form, nested_form and Twitter Bootstrap in Rails

我与影子孤独终老i 提交于 2019-12-07 02:56:27

问题


I'm using simple_form, nested_form and Twitter Bootstrap and trying to put the "Remove Link" from nested_form on the same line as the object.

Right now it looks like this:

http://grab.by/eKDS

and I want it to look like this:

http://grab.by/eKEc

Here's what my code looks like:

<%= cform.simple_fields_for :licensings do |lf| %>
  <%= lf.input :state, :collection => us_states, :wrapper => false %>
  <%= lf.link_to_remove "Remove this Licensing", :class => 'btn btn-mini btn-danger' %>
<% end %>

I've tried putting the second link_to_remove inside a block for the first lf.input but then the actual dropdown doesn't appear. I've looked through simple_form's code but I wasn't able to track down if there was a way to accomplish this.


回答1:


Thanks for the answers but I couldn't get either to work. I found the answer on the Google Groups mailing list:

https://groups.google.com/forum/?fromgroups#!topic/plataformatec-simpleform/hL9ek5svyAU

  <%= cform.simple_fields_for :licensings do |lf| %>
    <%= lf.input :state do %>
      <%= lf.input_field :state, :collection => us_states  %>
      <%= lf.link_to_remove "Remove this Licensing", :class => 'btn btn-mini btn-danger' %>
    <% end %>
  <% end %>



回答2:


Have you tried to add the class "inline" to your nested form?

<%= form_for @test, :html => { :class => 'form-inline' } do |f| %>
  <%= f.text_field :some_field, :class => 'text_field' %>
  <%= f.submit "Save", :class => 'btn btn-primary' %>
<% end %>



回答3:


As you can see in the documentation, you can create your custom wrapper. You must to add something like this in you simple_form's initializer :

config.wrappers :inline do |b|
  b.use :placeholder
  b.use :label_input
end

And use it like this :

<%= cform.simple_fields_for :licensings do |lf| %>
  <%= lf.input :state, :collection => us_states, :wrapper => inline %>
  <%= lf.link_to_remove "Remove this Licensing", :class => 'btn btn-mini btn-danger' %>
<% end %>


来源:https://stackoverflow.com/questions/11479381/adding-controls-inline-with-simple-form-nested-form-and-twitter-bootstrap-in-ra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!