Wednesday, May 2, 2012

set attribute from value of method

I am sure I am just doing this wrong, can someone point me in the right direction?



I need to set the value of effective_date to a modified format date



effective_date is an attribute of Request



class Request < ActiveRecord::Base

validates_uniqueness_of :effective_date

def format_date=(format_date)
date_a = format_date.split("/")
month, day, year = date_a
effective_date = Date.parse("#{year}-#{month}-#{day}")
end

def format_date
effective_date
end
end


Request.create(format_date: "04/21/2012") is not setting the value to effect_date





No comments:

Post a Comment