# Extend url\_for

**URL:** <https://www.ruby-forum.com/t/extend-url-for/89944>\
**Category:** Rails\
**Created:** [March 24, 2007, 2:21am UTC](https://www.ruby-forum.com/t/extend-url-for/89944 "2007-03-24T02:21:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [March 24, 2007, 2:21am UTC](https://www.ruby-forum.com/t/extend-url-for/89944/1 "2007-03-24T02:21:09Z")

</div>

Hi!

I want to extend the url\_for function (and some more functions) with a  
plugin.

Now I tried this:

# ExtendBase

module ActiveController  
class Base

```
def url_for
  'OK'
end

```

end  
end

def url\_for  
‘OK’  
end

But that didn’t have any effect. I have this in my init.rb:

# Include hook code here

require ‘extend\_base’

Anyone knows what could be wrong?

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [March 24, 2007, 2:30am UTC](https://www.ruby-forum.com/t/extend-url-for/89944/2 "2007-03-24T02:30:10Z")

</div>

Tried this also:

module ActionView  
module Helpers  
module UrlHelper  
alias\_method :force\_link\_to, :link\_to

```
  def link_to(name, options = {}, html_options = nil,

```

\*parameters\_for\_method\_reference)  
‘OK’  
end

```
end

```

end  
end

But nothing! Not even an error message…

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [March 25, 2007, 3:40am UTC](https://www.ruby-forum.com/t/extend-url-for/89944/3 "2007-03-25T03:40:15Z")

</div>

OK. The problem was that I mixed (well I believe that was the problem)  
unix and windows characters. When I threw the file away and typed it  
from scratch the problem was solved.

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [March 26, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/extend-url-for/89944/4 "2007-03-26T22:36:37Z")

</div>

Another problem arises. I have this in my plugin lib:

module ActionController  
module Routing  
def get\_default\_controller

ActionController::Routing::Routes.routes[0].requirements[:controller]  
end  
def get\_default\_action  
ActionController::Routing::Routes.routes[0].requirements[:action]  
end  
end  
end

But when I do this in a view: \<%= debug  
ActionController::Routing.get\_default\_controller %\>

I get this error: undefined method `get\_default\_controller’ for  
ActionController::Routing:Module

Does anyone know what could be the problem here?

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [March 26, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/extend-url-for/89944/5 "2007-03-26T22:50:39Z")

</div>

LeonB wrote:

> ```
> end
> 
> ```
> 
> end  
> end
> 
> But when I do this in a view: \<%= debug  
> ActionController::Routing.get\_default\_controller %\>
> 
> I get this error: undefined method `get\_default\_controller’ for  
> ActionController::Routing:Module
> 
> Does anyone know what could be the problem here?

Try it with a “self.” in front of the method name as in:

def self.get\_default\_controller  
…  
end

def self.get\_default\_action  
…  
end

–  
Michael W.
