Is it possible to give each record a differant css class?
Is there any way to give each record in a table its own css class? Im displaying records as partials but would like to be able to give each partial its own individual css attributes. Maybe a way of assigning css rules by a div's name and id of the record combined?
EDIT
Sorry for the poorly written question I'll try and explain in more detail.
I have a table of venue records being displayed on the index page in partials and want each one to have an icon placed on a map off to the left side of the screen (map_container). The map is just a hand drawn image as the background of a fixed width and height div.
Venue index.html.erb:
<div class="map_container">
</div>
<div class="filter_options_container">
<form class="filter_form", method="get">
<fieldset class="filter_form_fieldset">
<legend class="filter_form_fieldset_legend">Choose an area:</legend>
<% Area.all.each do |a| %>
<span class="filter_form_checkbox_label">
<%= check_box_tag("areas[]", a.id, false, :class => "styled")%>
<%= a.name %><br>
</span>
<% end %>
<input type="submit" value="Filter" />
</fieldset>
</form>
</div>
<div class="venue_partials_container">
<开发者_JS百科;%= render :partial => 'venue', :collection => @venues %>
<div class="clearall"></div>
<%= will_paginate @venues %>
<div class="venue_partial_button">
<%= link_to 'add a new venue', new_venue_path %>
</div>
</div>
<div class="clearall"></div>
I was thinking a way of doing this could be to make another table of icon records where one venue belongs to one icon and one icon belong to one venue. Then yielding the map div area to partials of the icon records. The differant css classes could then be something like:
.icon(with_venue_id_1) {
position: absolute;
top: 10px;
left: 10px;
}
.icon(with_venue_id_2) {
position: absolute;
top: 15px;
left: 20px;
}
etc etc....
Which I know is so horrifically bad it may bring a bit of sick in your mouth but my zero experience of programming ever has led me to this. I imagine theres so many better ways of doing it but this could work as a learning aid for me at least.
I would eventually like these icons and their positioning to be added from the running app itself but for now I'm happy just to get something working.
Thanks for any help, its much appreciated.
Something like this?
<% @record.each do |r| %>
<tr class="<%= r.id %>">
<!-- Or some other value from the record? -->
...
Not sure I understood the question completley.
精彩评论