Request: Make UrlHelper methods available for controllers

I had a need for accessing the methods in
ActionView::Helpers::UrlHelper in my controllers to conditionally
return link HTML to my views depending on login state etc.

I think that the UrlHelper should by default be added to all
Controllers and methods such as link_to made available for views using
helper_method :link_to.

What do you think?

I'm having problems using url_for in a controller. The original method
looks like this, but the @controller variable is unknown in this
context. However if I remove it, it goes in an endless loop for the
Hash case. Anyone?

      def url_for(options = {})
        options ||= {}
        url = case options
        when String
          escape = true
          options
        when Hash
          options = { :only_path =>
options[:host].nil? }.update(options.symbolize_keys)
          escape = options.key?(:escape) ? options.delete(:escape) :
true
          @controller.send(:url_for, options)
        when :back
          escape = false
          @controller.request.env["HTTP_REFERER"] ||
'javascript:history.back()'
        else
          escape = false
          polymorphic_path(options)
        end

        escape ? escape_once(url) : url
      end

Kristian,

If I understand what you are trying to do, then its a little
backwards. You really shouldn't be generating view stuff in the
controller. Instead you can create a class variable like @logged_in
and then use that to selectively show certain components in the view.

Allen Madsen
http://www.allenmadsen.com