donald
donald

Reputation: 23737

Rails 3: Return JSON with a specific variable

I have a method returning this:

  format.json  { render :json => @call, :include => :customer }

However, I want the @call.created_at to return as a more readable datetime.

How can I do that?

thanks

Upvotes: 0

Views: 415

Answers (1)

Gazler
Gazler

Reputation: 84150

You can create a method in your model to prettify the time.

class Call < ActiveRecord::Base
  def formatted_time
    #Pretty time
  end
end

format.json  { render :json => @call, :include => :customer, :methods => :formatted_time }

Upvotes: 1

Related Questions