Column types and date formatting

hi everyone,

working on my education tool here (im a teacher) and am having trouble
getting my times to format right. im using the scaffold code and
thought this would work:

<td>
  <% if lesson.send(column.name).type == "Time" %>
  <%=h lesson.send(column.name).strftime("%I:%M") %>
  <% else %>
  <%= h lesson.send(column.name) %>
  <% end %>
</td>

but that whole .time == “Time” thing doesnt seem to work. is there a
better way to do this? or, heck, one that works? ive looked all over
but im trying to get this running before the kids get there sept 4th
so im looking for some ninjas who know whats kickin…

thanks a heck of a bunch! ~ari (gold, but i really teach. im no
hollywood agent.)

well, lookee here. im going to answer my own questions (kind of), for
the sake of those (one person?) who come across it.

as ive been working with the excellent book “agile web development on
rails v2”, my answer is from there, chapter 6.4 (p. 76ish).

i got that snippet of code from the scaffolding generator. the
generator makes things generic, hence the
h lesson.send(column.name)
but once you’re working with specifics, you dont need to use the
generics (although there might be a way to do things with the
generics… cant figure it out). so you can specify column names and,
with the specified column name, do things with strftime which need
date fields…

 lesson.start_time.strftime("%I:%M")

thats pretty much it. naturally, each column needs to be specified -
instead of that lesson.send(column.name) thing up there… ~ari

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs