Reputation: 371
I couldn't find this anywhere and just went in circles with it so I figured someone else might benefit. How do you get access to rails url helpers in an engine?
For the core app, I can do something like this:
class Thingy < ActiveRecord::Base
include Rails.application.routes.url_helpers
...
end
But this doesnt work in models in an engine.
Upvotes: 24
Views: 6618
Reputation: 371
Looks like you need to specify the routes that're particular to your engine. So in your engine's model, for example, you can do this:
module Blog
class Stuffy
include Blog::Engine.routes.url_helpers
...
end
end
And now you can use the url helpers from your engine inside your engine's models.
Upvotes: 12