A pointer in the right direction needed please! I''m still getting my first app going, so this i believe should be a fairly simple problem. My Rails (3.0.0) app displays tables of events, with columns for Date / Band / venue / image etc. Currently it display the data in date order, which is great, but I''d also like to colour the table rows according to whether the date is old, within the next month, or after 1 month from now. I imagine I''ll want to make a differnt css class for each of these, with stuff like: old_date { <TD BGCOLOR="#ffff00">; } this_month { <TD BGCOLOR="#ff00ff">; } etc... but where in the code should I put the logic that determines which css class to use depending on the date? The view that displays the data is a simple table that goes through the array: ------ <table> <tr> <th>Date </th> <th>Image </th> <th>Event Name</th> <th>Band Name</th> <th>Venue</th> <th>Description</th> </tr> <% events_group.each do |event| %> <tr> <td><%= event.eventDate.to_formatted_s(:short) %></td> <td><%=h image_tag event.photo.url(:thumb) %></td> <td><%=h event.eventName %></td> <td><%=h event.bandName %></td> <td><%=h event.venue %></td> <td><%=h event.description %></td> <td><%= link_to ''Show'', event %></td> <td><%= link_to "Edit", polymorphic_path(event, :action => :edit) %></td> <td><%= link_to "Delete", event, :method => :delete, :confirm => ''Are you sure?'', :title => "Delete Event" %></td> </tr> <% end %> </table> ----- should the logic to change row color be in here somehow? Thanks in advance! Mike -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Jan 24, 2011 at 7:47 AM, Michael Baldock <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Currently it display the data in date order, which is great, but I''d > also like to colour the table rows according to whether the date is old, > within the next month, or after 1 month from now. > > I imagine I''ll want to make a differnt css class for each of these,> but where in the code should I put the logic that determines which css > class to use depending on the date?I''d put a helper method in my model that returns something like (one of) "past", "current", "future" and use those as my css class names. Then your view can include something like e.g. <td class="<%= event.age %>"> HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 24, 3:47 pm, Michael Baldock <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > but where in the code should I put the logic that determines which css > class to use depending on the date? >I''d write a view helper. you might either write a helper called something like class_for_event (and then use it like <td style=<%class_for_event event %>) or go for something like td_for_event which would create a td with the right class. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks guys, got it going now! Used Hassan''s suggestion of putting a method in the model, as I wasn''t sure how to make a view helper @Fred - just out of interest to make a view helper do I need to make a new file in views/shared? do I then define methods in here as normal? def methodname(args) body end how do I make it inherit all the functionality needed to compare dates / search the database? Thanks both for your help! M -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael, Helpers go in rails_root/app/helpers. Look in there. If you used scaffold, You should have files for controller specific helpers and a global helper file named application_helper.rb HTH, Dan On Jan 24, 1:02 pm, Michael Baldock <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Thanks guys, got it going now! > > Used Hassan''s suggestion of putting a method in the model, as I wasn''t > sure how to make a view helper > > @Fred - just out of interest > > to make a view helper do I need to make a new file in views/shared? > do I then define methods in here as normal? > def methodname(args) > body > end > > how do I make it inherit all the functionality needed to compare dates / > search the database? > > Thanks both for your help! > > M > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Cheers Dan, I''d thought those helpers were only available to the controllers, so didn''t know i could use them with the views as well, thanks for the insight. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 25, 11:03 pm, Michael Baldock <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Cheers Dan, I''d thought those helpers were only available to the > controllers, so didn''t know i could use them with the views as well, > thanks for the insight. >By default, you can only use them in views Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.