Ruby Regex Substitution – Benefit of Controllers

This site is generated on RoR, but published as static HTML. It goes way, way back, and the images are referenced in many ways. I think there is a decent chance that some images are referenced without quotes. I added a feature for mobile views years ago, so that I could easily browse with my phone. I figured others might enjoy that as well. I forget the logic, but it made more sense for me to put all of the articles in a directory off of the main URL with just an m subdirectory. The problems is that many of my image URLs are relative, so if I publish the images down a directory, they are all messed up. This was really easy to fix because I could just do a substitution at the controller level before I passed it on to the view. @uu.tag is the root domain URL element in an array that holds various pieces of the current domain. The i will ignore case (I wasn’t consistent). Here is the syntax of a regex substitution I used to do this:

@artrow.entry=@artrow.entry.gsub /img src=arts/i,'img src='+@uu.tag+'arts'
@artrow.entry=@artrow.entry.gsub /img src="arts/i,'img src="'+@uu.tag+'arts'
@artrow.entry=@artrow.entry.gsub /img src=nimages/i,'img src='+@uu.tag+'nimages'
@artrow.entry=@artrow.entry.gsub /img src="nimages/i,'img src="'+@uu.tag+'nimages'
@artrow.entry=@artrow.entry.gsub /img src=images/i,'img src='+@uu.tag+'images'  
@artrow.entry=@artrow.entry.gsub /img src="images/i,'img src="'+@uu.tag+'images'