Forum: Ruby on Rails extend url_for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1a9637acaccba514bf6c2cecf80c3f16?d=identicon&s=25 LeonB (Guest)
on 2007-03-24 02:21
(Received via mailing list)
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?
1a9637acaccba514bf6c2cecf80c3f16?d=identicon&s=25 LeonB (Guest)
on 2007-03-24 02:30
(Received via mailing list)
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...
1a9637acaccba514bf6c2cecf80c3f16?d=identicon&s=25 LeonB (Guest)
on 2007-03-25 03:40
(Received via mailing list)
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.
1a9637acaccba514bf6c2cecf80c3f16?d=identicon&s=25 LeonB (Guest)
on 2007-03-26 22:36
(Received via mailing list)
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?
Dfd6f9989147955682701da8227df8b4?d=identicon&s=25 Michael Wang (Guest)
on 2007-03-26 22:50
(Received via mailing list)
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 Wang
This topic is locked and can not be replied to.