ruby on rails - Using gsub to clean string and then truncate -



ruby on rails - Using gsub to clean string and then truncate -

i need remove characters string (computer mac address + junk...) , truncate leave first 18 characters.

currently, have next in model:

def popular_locations popular_locations = radacct.group(calledstationid).order('calledstationid desc').count end

that outputs list , count format needs adjustment search i'll do.

i tried adding this:

clean_mac_address = :calledstationid.gsub(/[^0-9a-z]/i, '')

but error undefined method `gsub' :calledstationid:symbol

-- edit --

initially calledstationid stored in db (radacct model) next format:

00-18-0a-21-44-7b:home office

this mac address plus ssid name.

i need strip out dashes , ssid because have model (locations) has list of mac addresses in format:

00:18:0a:21:44:7b

locations , radacct unrelated (radacct model sessions dumped into). need do count of sessions , grouping calledstationid (as seen above). we'll query locations table , work out location name. should left this:

location_name session_count school 2 home 12 office 89

i'm not sure how set errant : in there when model definition doesn't have it:

clean_mac_address = calledstationid.gsub(/[^0-9a-z]/i, '')

what mean clean variable before passing in:

def popular_locations # clean calledstationid calledstationid.gsub!(/[^0-9a-z]/i, '') # find , homecoming radacct.group(calledstationid).order('calledstationid desc').count end

ruby-on-rails ruby-on-rails-3

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -