views:

24

answers:

1

Rails: url_for to be available in a isolated class that must be instanced:

                    class ProfilePresenter < ActionController::Base

attr_reader :profile


def initialize(profile)
    super


    @a = url_for(:controller => 'profiles', :action => 'view', :profile_url => 'dd')
    @a

    @profile = profile
        end
     end

How to make the url_for work? i tried to extend the ActionController::Base and the ActionView::Base and i cant :s

A: 

I think you have to include "include ActionController::UrlWriter"

Try following

class ProfilePresenter < ActionController::Base
  include ActionController::UrlWriter
  attr_reader :profile


  def initialize(profile)
    super
    @a = url_for(:controller => 'profiles', :action => 'view', :profile_url => 'dd')
    @a
    @profile = profile
  end
end
Salil
I got this now: Missing host to link to! Please provide :host parameter or set default_url_options[:host]I prefered a way to not always have to set the host :s is that possible?
Totty