Wednesday, August 11, 2010

undefined method `rewrite' for <#String: URL_STRING>

Currently, I am working on a WEB API integration project for a leading tourism company in Australia. I am using RADIANT, MySQL, Ruby 1.8.7 and Rails 2.3.8. While working on an issue, I ran into a weird error: undefined method `rewrite' for <#String URL_STRING>.

I was defining an instance variable @url in the controller. Also, I was using a simple form_for tag in the view.


class SomeController < ApplicationController
def some_method
#some logic


- form_for :some_object, :url => @url do |f|
- #some form fields
= submit_tag 'submit'

Everything seemed normal. But, I started getting this weird error. After a bit of search, I came to know that link_to, url_for and similar method uses ActionController::Base @url instance variable to generate URLs. So, make sure that you don't use/define @url anywhere in your controllers/helpers.