Route helpers for non Trestle routes in views?
I've got to be missing something basic here as I have not used Trestle in a while, but I have a couple of routes that trigger downloads. These are on a bare basic "Dashboard" view.
Rails.application.routes.draw do
...
namespace :export do
get 'listing', action: :listing
end
end
Super basic, shows up in routes, works for the address bar. But in a view a simple:
<%= link_to "Export Listing", export_listing_path %>
Returns undefined local variable or method export_listing_path
Are the standard Rails route helpers not available in a view?
The Trestle engine uses an isolated namespace for its routes. This means that calls to your main application's routes must be prefixed with main_app.. e.g.
<%= link_to "Export Listing", main_app.export_listing_path %>
Alternatively you can append your routes directly within the Trestle engine:
Trestle::Engine.routes.draw do
# Your routes here
end
With this approach, you can call the routes directly from within the admin. The /admin path will also be automatically prefixed to route paths.
If it makes sense in your situation, I'd recommend defining your routes and actions directly within an admin resource:
Trestle.resource(:listings) do
controller do
def export
end
end
routes do
get :export, on: :collection
end
end
<%= admin_link_to "Export Listing", admin: :listings, action: :export %>