I'm learning rails and got this small app for learning purposes.
This is my folder structure, I'm trying to customize it for a DDDish approach:
This is my launcher_controller:
module Web
class LauncherController < ApplicationController
def launch
requestBody = params[:launcher]
render json: requestBody
end
end
end
And the routes.rb:
Rails.application.routes.draw do
scope module: 'web' do
post 'launcher/launch', action: 'launch', controller: 'launcher'
end
end
I already added the web and controllers path to the autoload_paths for zeitwerk to load the files in application.rb:
config.autoload_paths << config.root.join('app', 'web')
config.autoload_paths << config.root.join('app', 'web', 'controllers')
I can fire rails server up but when I call the controller's action I get:
ActionController::RoutingError (uninitialized constant Web)
I feel like this should be something really simple but I can't find the problem... I'm following the docs at https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use
So what basic concept am I missing here? Am I not defining the module at the launch_controller.rb file?
EDIT
Ok, based on the first answern I changed the module to Web in the module definition and 'web' on the routes.rb.
Now I got
ActionController::RoutingError (uninitialized constant Web)
I don't know if this could be a problem, but this is a web API only app. I generated the project with the following command:
rails new tracker-launcher -M -O -J -T --api
web
as the directory. But in the file you haveWebStuff
and in the routes you have:web_stuff
. It can't find the correct director bc you named it differently