Forum: Ruby on Rails NoMethod error for Time.year ??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B614e42d18c609ac4585d0aa0b13d856?d=identicon&s=25 rails (Guest)
on 2005-12-05 19:36
(Received via mailing list)
I have some code that works fine on my own system but the remote
server is crashing.  I'm sort of confused this should be very basic
Ruby.  My logs are telling me:

NoMethodError (undefined method `year' for Time:Class):
     /app/controllers/promotions_controller.rb:24:in `calendar'


I'm getting it from the following code:

  def calendar

      # Get the current time.
      t = Time.now

      # Get the first day of the month.
      @start_date = Date.new(t.year, t.month, 1)

      # Get the last day of the month.
      # Calculate the last day of the month.
      next_month = t.month+1
      next_year = t.year
      if t.month == 12
         next_month = 1
         next_year +=  1
      end

      # Assign the calculated time to a new date object.
      @end_date = Date.new(next_year, next_month, 1)-1

      # Grab the current promotions for the current time period.
      @promotion = Promotion.new
      @current_promotions = Promotion.current(@start_date,@end_date)

   end



Does anyone have any ideas?

Thanks,
Jim
This topic is locked and can not be replied to.