Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing   in Rails

I am trying to remove all  's in my model with the following method :

def about_us_sans_spaces
  self.about_us = replace(self.about_us, " ", " ")
end

Except! it turns out 'replace' isn't a method in rails. How would you remove the  's?

Mind you, I have already tried sanitized, simple_format. My view looks like this right now:

= truncate(sanitize(simple_format(organization.about_us_sans_spaces), :tags => ''), 125).titleize
like image 424
Trip Avatar asked Jun 08 '10 18:06

Trip


1 Answers

def about_us_sans_spaces
  self.about_us.gsub!(" ", "")
end

Edit: Note that gsub() also accepts regex, so you can catch all instances regardless of capitalization like so:

about_us.gsub(/ /i,"")
like image 145
user358390 Avatar answered Oct 04 '22 22:10

user358390