Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4631

Current year in Ruby on Rails

$
0
0

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.


Viewing all articles
Browse latest Browse all 4631

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>