Render Partial Vertically, div_for, partials collection
show.html.erb
<%= render :partia开发者_Python百科l => "hello", :collection => hello %>
_hello.html.erb
<%= div_for hello do %>
<%= link_to image_tag( hello.image, :size => "75x75"), '#' %>
<%= hello.updated_at.strftime('%m/%d/%Y') %>
<% end %>
Currently outputs:
hello1
hello2
etc.
Desired Output:
hello1 hello2 hello3 hello4
hello5 hello6 hello7 hello8
etc.
Basically I want to render the item side by side in columns instead of one per a line. I've tried using a table and I know how to float divs, but the problem I'm having is that rails generates the div class and id, and I don't know how to do this short of creating in the css file special rules for id1, id2, id3, id4, ...id200, etc. I was wondering if their was an easier way to put a specific number of items on one line.
You can add a class to div_for, like this
<%= div_for(hello, :class => "SOMECLASS" do %>
<%= link_to image_tag( hello.image, :size => "75x75"), '#' %>
<%= hello.updated_at.strftime('%m/%d/%Y') %>
<% end %>
and then you can style the div with float:left, so that the divs will be side by side.
精彩评论