Undefined method `rewrite' for #<String

Hi.

i made a simple controller thats_not_users

then have a simple line in my layout rhtml file:
<%= link_to “Users”, :controller => “users”, :action => “index”
%>

And I’m getting this error message within the layout template when
loading the controller thats_not_users:

NoMethodError in Controller
undefined method `rewrite’ for #<String

weird eh?

Dominic S. wrote:

Hi.

i made a simple controller thats_not_users

then have a simple line in my layout rhtml file:
<%= link_to “Users”, :controller => “users”, :action => “index”
%>

And I’m getting this error message within the layout template when
loading the controller thats_not_users:

NoMethodError in Controller
undefined method `rewrite’ for #<String

weird eh?

Interesting – I ran into the same problem.

In my case, it’s

ActionView::TemplateError (undefined method rewrite' for #<String:0xb7770f34>) on line #4 of app/views/game/_copyright.rhtml: /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:488:inurl_for’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:27:in
url_for' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:59:inlink_to’
#{RAILS_ROOT}/app/views/game/_copyright.rhtml:4:in
`_run_rhtml_game__copyright’

[…more not-very-useful stack trace]

The “offending” line was:

<%= link_to “How this Works”, :controller => ‘members’, :action =>
‘howitworks’%>

Anybody got any ideas?

–Al Evans

Al Evans wrote:

[Stack trace from ‘undefined method `rewrite’ for #<String…’]

ActionView::TemplateError (undefined method rewrite' for #<String:0xb7770f34>) on line #4 of app/views/game/_copyright.rhtml: /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:488:inurl_for’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:27:in
url_for' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:59:inlink_to’
#{RAILS_ROOT}/app/views/game/_copyright.rhtml:4:in
`_run_rhtml_game__copyright’

[…more not-very-useful stack trace]

The “offending” line was:

<%= link_to “How this Works”, :controller => ‘members’, :action =>
‘howitworks’%>

Anybody got any ideas?

I’ve run across this a couple of times today. It’s sporadic – if I
press the reload button on the browser, it doesn’t happen again.

For what it’s worth, in both cases it seemed to happen the next time
‘url_for’ was called after calling “deliver__email”.
“perform_deliveries” is set false.

Maybe that will ring a bell with anyone?

One of the URLs was in a controller, one in an rhtml file.

Using literal urls, i.e. “/some_controller/some_action” solved the
problem in both cases.

Anybody else seen this?

–Al Evans

I just repro’ed it by assigning a string to the @url instance variable.
Make sure your controller/helper/view code is NOT assigning to @url
anywhere (either directly or indirectly).

link_to/url_for and related uses the ActionController::Base @url
instance variable to generate URLs, so if you (or plugins you’ve
installed) clobber it somehow, you’ll get this error.

Many Thanks Eden