I have a Rails 4 app where all controllers and views are divided into two namespaces, an agent-facing backend
and a customer-facing frontend
:
MyApp::Application.routes.draw do
constraints subdomain: "admin" do
namespace :backend do
resources :events
end
end
constraints subdomain: /.+/ do
namespace :frontend do
resources :events
end
end
end
Additionally, all controllers inherit from either BackendController
or FrontendController
:
controllers
├── application_controller.rb
├── backend
│ ├── events_controller.rb
├── backend_controller.rb
├── frontend
│ └── events_controller.rb
├── frontend_controller.rb
Right now everything that needs to generate a path has to be prefixed with the namespace, such as respond_with [:backend, @event]
or form_for [:backend, @event]
.
Is there a way to set a default namespace for URL helpers per-controller, so that respond_with @event
called from a controller that inherits from BackendController automatically assumes the correct namespace?