0
날짜를 빼기 위해 노력하고 있지만 월 만 빼기. params [: date]를 mm/dd/yyyy 형식으로보기에서 컨트롤러로 전달합니다. 내가 helpers.rb에서 컨트롤러레일에서 루비의 날짜를 빼는 방법
include AgeCalculatorHelper
def new
@age = AgeCalculator.date_subtr(params[:date])
render :index
end
의 코드가
require 'date'
class AgeCalculator
def self.date_subtr(date)
(Date.today.strftime('%m/%d/%y').to_i - date.to_i)
end
내가 오류 undefined method
을 통해 to_i
없이 시도 - 'for "08/21/16":String Did you mean? [email protected]
같은 출력 년 개월 일을 반환 할 수 있습니다. :) – Mani
이것이 당신이하려는 일을합니까? – kcdragon
정확하지는 않습니다. 나는 일, 월, 년을 보여주고 싶습니다. – Mani