I have a model with a field called "type" and a field called "value". The type field will determine how the "value" is parsed before rendering. I want this to be easily extendible, so I'm putting a variety of "formatter" classes in my lib folder.
One of my "formatters" has a call to url_for:
class CustomTypeFormatter
include ActionView::Helpers::TextHelper
include ActionView::Helpers
def show
raw sanitize( auto_link( value ) )
end
def get_url(page)
url_for( :controller => :my_controller, :action => :show, :path => page.path )
end
end
The problem is, url_for is raising this error:
undefined local variable or method `_routes'
I think I'm just missing an include. Does anyone have an idea what it should be?
**UPDATE***
Here's part of the stack trace:
actionpack (3.0.7) lib/action_dispatch/routing/url_for.rb:131:in `url_for'
actionpack (3.0.7) lib/action_view/helpers/url_helper.rb:99:in `url_for'
So I think it must be some ActiveDispatch dependency, although I cannot figure out
Victory!
include ActionView::Helpers
include ActionDispatch::Routing
include Rails.application.routes.url_helpers
via http://apidock.com/rails/ActionController/UrlWriter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With