undefined method `rewrite' for #<String

7 views
Skip to first unread message

Dominic Son

unread,
Sep 27, 2006, 2:42:07 PM9/27/06
to rubyonra...@googlegroups.com
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?

--
Posted via http://www.ruby-forum.com/.

Al Evans

unread,
Oct 5, 2006, 9:14:13 AM10/5/06
to rubyonra...@googlegroups.com
Dominic Son 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:in
`url_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:in
`link_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

unread,
Oct 5, 2006, 5:21:24 PM10/5/06
to rubyonra...@googlegroups.com
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:in
> `url_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:in
> `link_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_<something>_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?

eden li

unread,
Oct 6, 2006, 12:49:04 AM10/6/06
to Ruby on Rails: Talk
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.

patrick divan

unread,
Dec 27, 2010, 12:50:04 PM12/27/10
to rubyonra...@googlegroups.com
Many Thanks Eden
Reply all
Reply to author
Forward
0 new messages