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.
TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.
Module ActionView::Helpers::UrlHelper. Provides a set of methods for making links and getting URLs that depend on the routing subsystem (see ActionDispatch::Routing). This allows you to use the same format for links in views and controllers.
A Route Driver Helper is responsible for safely and efficiently assisting in delivering, and unloading product sold to customers.
rake routes will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
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.
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