Nokogiri::CSS::SyntaxError when rails model method called from rails console, but runs fine when I copy and past the method into the rails console-Collection of common programming errors

I’m using Nokogiri in Rails 3.2.11 to do some screen scraping. I have this one very long method that when I copy and paste line by line into the rails console it runs flawlessly, but when I call it in the console form my model file, it breaks, sending this error: Nokogiri::CSS::SyntaxError: unexpected ‘$’ after ”

Here’s the method (it’s 2, the first calls the second). Any help at all would be much appreciated:

def self.recurse_craigs(add = 'o')
  years = "#{MIN_YR}%7C05%7C#{MIN_YR+1}%7C06%7C#{MIN_YR+2}%7C07%7C#{MIN_YR+3}%7C08%7C#{MIN_YR+4}%7C09%7C#{MIN_YR+5}%7C#{MIN_YR+6}%7C#{MIN_YR+7}"
  CraigsLocalSite.all.each do |site|
    url = "http://#{site.city_for_url}.craigslist.org/search/ct#{add}?zoomToPosting=&altView=&query=#{years}&srchType=T&minAsk=#{MIN_PRICE}&maxAsk=#{MAX_PRICE}"
    get_craigs_page(url, site, add)
  end
end

private


def self.get_craigs_page(url, craigs_site, add, recursion_level = 0)
  if add == 'o'
    owner = true
  elsif add == 'd'
    dealer = true
  end
  dqers = ['rebuil', 'salvag', 'salvaj', 'rebil', 'ribil', 'over payment', 'take over', 'payments']
  begin
    Timeout::timeout(10) do
      @doc = Nokogiri::HTML(open(url))
    end
  rescue
  end
  new_posts = 0
  if defined? @doc
    @doc.css('.row').each do |row|
      #### DO SOME STUFF, IRRELEVANT BECAUSE THIS IS WHERE METHOD BREAKS

Here’s the error call stack:

Nokogiri::CSS::SyntaxError: unexpected '$' after ''
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/css/parser_extras.rb:87:in `on_error'
  from (eval):3:in `_racc_do_parse_c'
  from (eval):3:in `do_parse'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/css/parser_extras.rb:62:in `parse'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/css/parser_extras.rb:79:in `xpath_for'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/css.rb:24:in `xpath_for'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/xml/node.rb:210:in `block in css'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/xml/node.rb:209:in `map'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/xml/node.rb:209:in `css'
  from [app path]/app/models/feed_entry.rb:348:in `block in get_craigs_page'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/xml/node_set.rb:239:in `block in each'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/xml/node_set.rb:238:in `upto'
  from [gempath]/nokogiri-1.4.7/lib/nokogiri/xml/node_set.rb:238:in `each'
  from [app path]/app/models/feed_entry.rb:335:in `get_craigs_page'
  from [app path]/app/models/feed_entry.rb:311:in `block in recurse_craigs'
  from [app path]/app/models/feed_entry.rb:309:in `each'
  from [app path]/app/models/feed_entry.rb:309:in `recurse_craigs'
  from (irb):1
  from [gempath]/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
  from [gempath]/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
  from [gempath]/railties-3.2.11/lib/rails/commands.rb:41:in `'
  from script/rails:6:in `require'