views:

110

answers:

1

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
+6  A: 
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,"")
That's fantastic! Totally worked. Not entirely sure what you mean by '/ /i,"" would that do the same thing as the previous example?
Trip
It would also replace instances of '' etc.
Tomas Markauskas
No, they do different things.gsub(" ", "") will replace the literal " " with "", while gsub(/ /i, "") will replace " ", "", "" or any other possible capitalization combination. / / matches " ", the "i" flag makes it case insensitive.http://ruby-doc.org/core/classes/Regexp.html