Ruby I/O: Rails rake task is trying to find and replace certain lines of code, but doesn't
===

I'm working on a rake task that changes the meta tags for certain pages.  These tags are defined in the controller. The rake task is meant to open the controller file, find any line with the phrase "@meta_tag" in it, and then re-write that line per the replace_line(line) method.  When I run the rake task, I don't get any errors, but it also doesn't make any changes.  

I think my problem is in the 'r+' line.  Do I need to open the file in one line and write to it in another line of code?  

    require 'rake'
    namespace :meta_tags do
      desc 'changes the meta tags'
      task :update => :environment do 
        
        regex = /@meta_tag/
        found = false
        file = File.open('app/controllers/site_controller.rb', 'r+')
        file.each_line do |line|
          replace_line(line) if(found)
          found = true if(line =~ regex)
        end
      end
      
      def replace_line(line)
        meta_tags = MetaTag.all.map { |tag| tag["tag"] }
        new_tag = meta_tags.sample(1)[0]
        line = "@meta_tag = #{new_tag}"
      end
    end

If you see what I'm doing wrong, please let me know.