Simple question, what's the correct way of accessing URL helpers from inside a stimulus controller?
Right now we're having to do some rather smelly code where the controller gets passed though erb, to allow something like this:
// app/javascript/controllers/stage_filter_controller.js.erb
import { Controller } from 'stimulus'
export default class StageFilterController extends Controller {
// snip...
getPlotsUrl(siteId) {
var url = '<%= Rails.application.routes.url_helpers.plot_options_path %>'
url += `?site=${siteId}`
return url;
}
}
I don't like this at all, but don't know how to do it any other way.