Here is a simple method that returns number of days for wanted month and year. If year is ommited current year is selected.
Now, let’s assume we have a date from a database, and we want to find number of days in a month from that date.
But with two more lines of code
we could find it like this:
It is worth mentioning that if String is passed as an argument
we will get an ERROR, because first argument must be a Fixnum or a Date.
If you want to use this as a helper in Rails, create the file date_helper.rb in a lib directory of your app, and put this in:
and then add this line to config/environment.rb