Hi, I''d like to upcase a variable before it is saved, but I''m not sure how to access the incoming param or where this work should be performed: In my update method, I have: @device = Device.find(params[:id]) params[:device[macaddress]].upcase <-- problem code if @device.update_attributes(params[:device]) ....usual stuff here ''macaddress'' is the variable I''d like to upcase. Does anybody have suggestions? - Nic.
Nic, In your model, I think you want to hook into the before_save callback, like: before_save :normalize def normalize macaddress.upcase! #other modifications here end Hope that helps, Regards, Ed C. On 12/19/05, Nic Werner <nicwerner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''d like to upcase a variable before it is saved, but I''m not sure how > to access the incoming param or where this work should be performed: > > In my update method, I have: > > @device = Device.find(params[:id]) > params[:device[macaddress]].upcase <-- problem code > if @device.update_attributes(params[:device]) > ....usual stuff here > > ''macaddress'' is the variable I''d like to upcase. > > Does anybody have suggestions? > > - Nic. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Mon, Dec 19, 2005 at 08:48:20PM -0800, Nic Werner wrote:> I''d like to upcase a variable before it is saved, but I''m not sure how > to access the incoming param or where this work should be performed: > > In my update method, I have: > > @device = Device.find(params[:id]) > params[:device[macaddress]].upcase <-- problem code > if @device.update_attributes(params[:device]) > ....usual stuff here > > ''macaddress'' is the variable I''d like to upcase. > > Does anybody have suggestions?You could use a before_save callback in the Device model. class Device < ActiveRecord::Base before_save :normalize_macaddress # ... private def normalize_macaddress self.macaddress = macaddress.upcase if macaddress end end marcel -- Marcel Molina Jr. <marcel-WRrfy3IlpWYdnm+yROfE0A@public.gmane.org>