In my view, I use a <%= f.text_field :latlon %>
to edit the latlon
attribute (not an ActiveRecord column). When saving, I want to parse latlong
and split it into lat
and lon
in a before_save
callback.
I don't know how to access to the params of the latlon
variable inside the callback. I have tried self.latlong
but that calls the same attr_reader
as the lat
and lon
attributes.
I know I can do this in the controller but, this is model logic, no?
#app/models/bla.rb
class Bla < ActiveRecord::Base
attr_accessible :name, :lat, :lon, :latlon #but latlon is not an ActiveRecord Attribute
before_save :foo
def latlon
"#{lat}, #{lon}"
end
attr_writer latlon
private
def foo
self.lat = # regex that parse latlon
self.lon = # regex that pase coors
end
end