How can I get current year in Ruby on Rails?
I tried a variety of things, including
- Date.current.year
- Time.now.year
The problem is they return the previous year in cases where year changes after launching the server (eg. after new year's).
Relevant code:
Model brewery.rb
class Brewery < ActiveRecord: :Base...validates :year, numericality: { only_integer: true, less_than_or_equal_to: Date.today.year }...
Problem occurs when creating a new brewery, so I assumed Date.today.year would be evaluated whenever that action takes place.