Two Noob Questions

I am building my first application, and have a couple of quick
questions. Hopefully someone can point me in the right direction.

  1. When I created my model , I noticed a field named “created_at” ,
    which comes in handy. But when I retrieve the value , it comes back
    very long and un-user friendly. How do I return this date as: Jun 23
    08 , or March 21, 2008 , etc?

  2. In my layout , I have some simple CSS which formats some tabs
    ( li’s ). If we are on a certain page , I would add “class = current”
    to make the tab background a different color. How do I differentiate
    which page I am on , so I can add the class current to the proper
    page?

Thanks! Glad to be on board.

JT

JT,

  1. Look through strftime at
    class Time - RDoc Documentation
    e.g: created_at.strfime(‘%B %d’) == ‘January 01’

  2. controller.controller_name and controller.action_name give you the
    current controller and action in a view.

Here’s some ideas on tab helpers:
http://www.therailsway.com/2007/6/4/free-for-all-tab-helper
http://www.therailsway.com/2007/6/28/free-for-all-tab-helper-summary

There’s also params[:controller] and params[:action] that do the same
thing as controller.controller_name and controller.action_name
respectively.

On Tue, Aug 26, 2008 at 7:52 PM, trope [email protected] wrote:

I am building my first application, and have a couple of quick
questions. Hopefully someone can point me in the right direction.

  1. When I created my model , I noticed a field named “created_at” ,
    which comes in handy. But when I retrieve the value , it comes back
    very long and un-user friendly. How do I return this date as: Jun 23
    08 , or March 21, 2008 , etc?

strftime is your answer

http://ruby-doc.org/core/classes/Time.html#M000297

Make sure to set your time zone in environment.rb

  1. In my layout , I have some simple CSS which formats some tabs
    ( li’s ). If we are on a certain page , I would add “class = current”
    to make the tab background a different color. How do I differentiate
    which page I am on , so I can add the class current to the proper
    page?

In your controller set an instance variable such as:

@css_class = “class = current”

Use it in your page as:

<%= @css_class %>