I am trying to make gsub on my column before save or update.
Here is my controller:
def dansk(text)
self.text.gsub('å', 'å')
self.text.gsub('Å', 'Å')
self.text.gsub('æ', 'æ')
self.text.gsub('Æ', 'Æ')
self.text.gsub('ø', 'ø')
self.text.gsub('Ø', 'Ø')
end
def update
@photographer = Photographer.find(params[:id])
@photographer.update_attributes(params[:photographer])
@photographer.text = dansk(params[:photographer][:text])
@photographer.text = dansk(params[:photographer][:name])
!@photographer.save
flash[:notice] = " "
render_action 'edit'
end
What are I am doing wrong and why are the text and name not being “gsubbed” ?
UPDATE:
My helper:
def convert_html_entities(text)
text.gsub(/å/,"å")
text.gsub(/æ/,"æ")
text.gsub(/ø/,"ø")
text.gsub(/©/,"©")
text = text.gsub(/["]/, '"')
end
You should do this at the Model level (maybe put your dansk method in a module if you want to keep things DRY).
In your controller, you’d only need: