I have a controller:
class StatsController < ApplicationController
require 'time'
def index
@started = "Thu Feb 04 16:12:09 UTC 2010"
@finished = "Thu Feb 04 16:13:44 UTC 2010"
@duration_time = stats_duration(@started, @finished)
end
private
def stats_duration(started, finished)
time_taken = distance_of_time_in_words(Time.parse(started), Time.parse(finished))
time_taken
end
end
It takes in a start and end time and calculates the duration between the times.
When I run this I get the following error:
private method `gsub!’ called for Thu
Feb 04 16:12:09 UTC 2010:Time
Why is this happening?
private method gsub! called when using
Time.parseusually means that you have calledparsewith aTimeobject rather than aStringso it sounds like your code is actually trying to parse the time twice.e.g.