# Strange error: undefined method \`rewrite'

**URL:** <https://www.ruby-forum.com/t/strange-error-undefined-method-rewrite/80097>\
**Category:** Rails\
**Created:** [March 12, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/strange-error-undefined-method-rewrite/80097 "2006-03-12T16:30:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vlad\_Berditchevskiy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/6de8d8/32.png) [@Vlad\_Berditchevskiy](https://www.ruby-forum.com/u/Vlad_Berditchevskiy)\
**Post date:** [March 12, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/strange-error-undefined-method-rewrite/80097/1 "2006-03-12T16:30:56Z")

</div>

Hi,

when I generate a new rails project with a simple scaffolded controller,  
I get a strange error message, whenever it tries to call the url\_for  
method, for example:

,----  
| undefined method `rewrite' for #<Url:0xb7675e64> | | Extracted source (around line #7): | | 4: </p> | 5: <% end %> | 6: | 7: <%= link_to 'Edit', :action => 'edit', :id => @url %> | | 8: <%= link_to 'Back', :action => 'list' %> `----

,----  
| /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:1501:in `method_missing' | /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:448:in `url\_for’  
| /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_view/helpers/url\_helper.rb:18:in `url_for' | /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_view/helpers/url_helper.rb:49:in `link\_to’  
| #{RAILS\_ROOT}/app/views/urls/show.rhtml:7  
`----

I looked at the source and found out that the error originates from the  
following code:

,----  
| def url\_for(options = {}, \*parameters\_for\_method\_reference) #:doc:  
| case options  
| when String then options  
| when Symbol then send(options, \*parameters\_for\_method\_reference)  
| when Hash then @url.rewrite(rewrite\_options(options))  
| end  
| end  
`----

Where is this ‘rewrite’ method supposed to be and why can’t it be found?

–  
\ / removed\_email\_address@domain.invalid  
/lad [http://www.hashbang.de](http://www.hashbang.de)

---

<div class="post-metadata">

**Author:** ![Vlad\_Berditchevskiy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/6de8d8/32.png) [@Vlad\_Berditchevskiy](https://www.ruby-forum.com/u/Vlad_Berditchevskiy)\
**Post date:** [March 12, 2006, 5:17pm UTC](https://www.ruby-forum.com/t/strange-error-undefined-method-rewrite/80097/2 "2006-03-12T17:17:32Z")

</div>

Vlad Berditchevskiy wrote:

> ,----  
> | undefined method `rewrite' for #<Url:0xb7675e64> | | Extracted source (around line #7): | | 4: </p> | 5: <% end %> | 6: | 7: <%= link_to 'Edit', :action => 'edit', :id => @url %> | | 8: <%= link_to 'Back', :action => 'list' %> `----
> 
> ,----  
> | /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:1501:in `method_missing' | /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:448:in `url\_for’  
> | /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_view/helpers/url\_helper.rb:18:in `url_for' | /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_view/helpers/url_helper.rb:49:in `link\_to’  
> | #{RAILS\_ROOT}/app/views/urls/show.rhtml:7  
> `----

You can’t use Url as a model name.

joey\_\_  
[http://www.feedreed.com](http://www.feedreed.com)

---

<div class="post-metadata">

**Author:** ![Vlad\_Berditchevskiy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/6de8d8/32.png) [@Vlad\_Berditchevskiy](https://www.ruby-forum.com/u/Vlad_Berditchevskiy)\
**Post date:** [March 12, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/strange-error-undefined-method-rewrite/80097/3 "2006-03-12T18:33:04Z")

</div>

joey\_\_ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> You can’t use Url as a model name.

Thank you for the explanation, this error was driving me crazy! 🙂

BTW, what’s wrong with the model name Url? Are there other “forbidden”  
model names?

–  
\ / removed\_email\_address@domain.invalid  
/lad [http://www.hashbang.de](http://www.hashbang.de)
