Rails: Error making get request to local server - ruby-on-rails

New to ruby/rails, haven't been able to find a lot of resources and/or latest stack overflow threads on this topics so posting
I can see api/articles route when in command line when I try rails route, however, when trying to make a get request I am receiving the error
ActionController::RoutingError: No route matches [GET] \"/api/articles\"
Below are my relevant files.
routes.rb
Rails.application.routes.draw do
namespace :api do
resources :articles, only: [:index, :show]
end
end
articles_controller.rb
module Api
class ArticlesController < ApplicationController
def index
articles = Article.order('created_at DESC');
render json: {
status: 'success', message: 'loaded articles', data: articles
},
status: :ok
end
end
Articles model
class Article < ApplicationRecord
validates :title, presence :true
validates :body, presence :true
end
full stacktrace:
ActionController::RoutingError (No route matches [GET] "/api/articles"):
actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
railties (5.2.3) lib/rails/engine.rb:524:in `call'
puma (3.12.1) lib/puma/configuration.rb:227:in `call'
puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
puma (3.12.1) lib/puma/server.rb:474:in `process_client'
puma (3.12.1) lib/puma/server.rb:334:in `block in run'
puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'

Related

No route matches [POST] "/webhooks/orders/fulfilled" Shopify rails

I use the shopify CLI to create a Shopify Rails App, and I want to integrate a webhook, this is my configuration:
config/initializers/shopify_app.rb
ShopifyApp.configure do |config|
config.application_name = "My Shopify App"
config.api_key = ENV['SHOPIFY_API_KEY']
config.secret = ENV['SHOPIFY_API_SECRET']
config.old_secret = ""
config.scope = ENV['SCOPES'] # Consult this page for more scope options:
# https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes
config.embedded_app = true
config.after_authenticate_job = false
config.api_version = "2020-10"
config.shop_session_repository = 'Shop'
config.allow_jwt_authentication = true
config.webhooks = [
{topic: 'orders/fulfilled', address: 'https://4d132e9604.ngrok.io/webhooks/orders/fulfilled', format: 'json'},
]
end
config/routes.rb
Rails.application.routes.draw do
root :to => 'home#index'
mount ShopifyApp::Engine, at: '/'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
app/jobs/fulfilled_job.rb
class FulfilledJob < ActiveJob::Base
def perform(shop_domain:, webhook:)
shop = Shop.find_by(shopify_domain: shop_domain)
puts "called hook!!!!"
if shop.nil?
logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'")
return
end
puts "before shop"
shop.with_shopify_session do
puts "in shop with_shopify_session"
end
end
end
The webhooks was registered successfully on my store, and it is called without a problem, but in my app, I can process it, I receive a No route matches [POST] "/webhooks/orders/fulfilled" error , but I think it registers well:
this is the full stacktrace:
Started POST "/webhooks/orders/fulfilled" for 127.0.0.1 at 2020-11-09 12:18:26 -0500
ActionController::RoutingError (No route matches [POST] "/webhooks/orders/fulfilled"):
actionpack (6.0.3.4) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
web-console (4.1.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.1.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.1.0) lib/web_console/middleware.rb:17:in `catch'
web-console (4.1.0) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.4) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.4) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.4) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.4) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
shopify_app (15.0.0) lib/shopify_app/middleware/jwt_middleware.rb:23:in `call_next'
shopify_app (15.0.0) lib/shopify_app/middleware/jwt_middleware.rb:14:in `call'
shopify_app (15.0.0) lib/shopify_app/middleware/same_site_cookie_middleware.rb:11:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
webpacker (4.3.0) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.3.4) lib/rails/engine.rb:527:in `call'
puma (4.3.6) lib/puma/configuration.rb:228:in `call'
puma (4.3.6) lib/puma/server.rb:713:in `handle_request'
puma (4.3.6) lib/puma/server.rb:472:in `process_client'
puma (4.3.6) lib/puma/server.rb:328:in `block in run'
puma (4.3.6) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
Any thoughts? maybe I forget some configuration?

Create User with Endpoint - Routing error

User must be created from an API endpoint it has only one attribute :nick
I sent the Post request with PostMan but I have a routing error
Here are my routes:
resources :users
In Users Controller I have new and createaction, like so:
def new
#user = User.new
end
def create
#user = User.new(user_params)
if #user.save!
head :created
else
head :no_content
end
end
In Postman :
I have selected Post and the url is http://localhost:3000/users/new
In Header I have:
Key Value
Content-Type Application/Json
Here is the body:
{
"data": {
"type": "user",
"attributes": {
"nick": "Liwis"
}
}
}
When I send the request it returns that:
ActionController::RoutingError (No route matches [POST] "/users/new"):
actionpack (6.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.0) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.0) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.0) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.0) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.0) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.2) lib/rack/method_override.rb:24:in `call'
rack (2.2.2) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.0) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.0) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.0) lib/rails/engine.rb:526:in `call'
puma (4.3.3) lib/puma/configuration.rb:228:in `call'
puma (4.3.3) lib/puma/server.rb:682:in `handle_request'
puma (4.3.3) lib/puma/server.rb:472:in `process_client'
puma (4.3.3) lib/puma/server.rb:328:in `block in run'
puma (4.3.3) lib/puma/thread_pool.rb:134:in `block in spawn_thread'

Why my rails is not auto-loading the app folder?

I just start using rails and now doing some basic drills to handle requests. I've created the project with rails new (project_name) --api --skip-active-record and following this video: https://www.youtube.com/watch?v=QojnRc7SS9o, since I don't want to use database yet so I added the --skip-active-record
...After tons of uninitialized errors, I added this line in application.rb
config.after_initialize do
# it should be defined in 'application_controller.rb'
puts "def: #{defined? ApplicationController}" # => nil
end
then I run rails s it says it's undefined(aka nil)...
Of course I can require the app folder manually, but it seems just reinvent the wheel, any way to fix this?
Additional info I run with the command that googled from another article, maybe will help:
>> ruby bin/rails runner "ActiveSupport::Dependencies.autoload_paths.each{|line| puts line}"
F:/Programming/RoR/api_test/app/channels
F:/Programming/RoR/api_test/app/controllers
F:/Programming/RoR/api_test/app/controllers/concerns
F:/Programming/RoR/api_test/app/jobs
F:/Programming/RoR/api_test/app/mailers
F:/Programming/RoR/api_test/app/models
F:/Programming/RoR/api_test/app/models/concerns
F:/Programming/RoR/api_test/test/mailers/previews
Edit: The full error trace of the uninitiated error:
Started GET "/api/v0/handshake" for ::1 at 2019-07-11 17:24:30 +0800
ActionController::RoutingError (uninitialized constant Api::V0::HandshakeController):
activesupport (5.2.3) lib/active_support/inflector/methods.rb:285:in `const_get'
activesupport (5.2.3) lib/active_support/inflector/methods.rb:285:in `block in constantize'
activesupport (5.2.3) lib/active_support/inflector/methods.rb:281:in `each'
activesupport (5.2.3) lib/active_support/inflector/methods.rb:281:in `inject'
activesupport (5.2.3) lib/active_support/inflector/methods.rb:281:in `constantize'
actionpack (5.2.3) lib/action_dispatch/http/request.rb:88:in `controller_class_for'
actionpack (5.2.3) lib/action_dispatch/http/request.rb:81:in `controller_class'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:46:in `controller'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:840:in `call'
rack (2.0.7) lib/rack/etag.rb:25:in `call'
rack (2.0.7) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.7) lib/rack/head.rb:12:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
railties (5.2.3) lib/rails/engine.rb:524:in `call'
puma (3.12.1) lib/puma/configuration.rb:227:in `call'
puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
puma (3.12.1) lib/puma/server.rb:474:in `process_client'
puma (3.12.1) lib/puma/server.rb:334:in `block in run'
puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
My controller file (path: app/controllers/api/v0/handshake.rb)
module Api
module V0
class HandshakeController < ApplicationController
def index
render json: {status: 'SUCCESS', message: 'Hello World!'}, status: :ok
end
end
end
end
and the routes.rb
Rails.application.routes.draw do
namespace 'api' do
namespace 'v0' do
resources :handshake
end
end
end
OK I got it. The problem is my filename is unmatched with the rail's autoload file structure as it says here, after I renamed handshake.rb to handshake_controller.rb and it worked

Unable to perform Enqueue now in sidekiq-cron UI after authentication

I am using sidekiq gem to process the background jobs and sidekiq-cron to schedule the jobs at certain time interval.
In config/routes.rb, I have added the following to provide authentication to sidekiq UI endpoint.
authentication = ->req { req.env["warden"].authenticate!}
constraints authentication do
mount Sidekiq::Web => '/sidekiq'
end
When I hit Enqueue now button (Refer attached image), It throws following error and job not added to queue. It was working without authentication.
ActionController::RoutingError (No route matches [GET] "/sidekiq/cron/my_report/enque"):
F, [2019-04-11T11:00:27.684536 #9365] FATAL -- :
F, [2019-04-11T11:00:27.684733 #9365] FATAL -- : actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
railties (5.2.3) lib/rails/engine.rb:524:in `call'
puma (3.12.1) lib/puma/configuration.rb:227:in `call'
puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
puma (3.12.1) lib/puma/server.rb:474:in `process_client'
puma (3.12.1) lib/puma/server.rb:334:in `block in run'
puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
I'm using Sidekiq Pro and cron gem. Maybe my configuration can help you (although I use a basic HTTP auth form).
In application.rb:
require 'sidekiq-pro'
require 'sidekiq/pro/web'
require 'sidekiq/cron/web'
class Application < Rails::Application
Sidekiq::Web.use Rack::Auth::Basic do |username, password|
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(Rails.application.secrets.sidekiq_username)) &
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(Rails.application.secrets.sidekiq_password))
end if Rails.env.production?
end
Then on routes.rb I only have this:
mount Sidekiq::Web => '/sidekiq'
So, every time I go to some-url/sidekiq, an auth form will appear.
Hope this can help you.

Rails controllers in modules fail in production with ActionController::RoutingError (uninitialized constant Admin::

In our app we are using modules to organize some controllers. Here's what the directory structure looks like:
app/
controllers/
admin/
products/
reviews_controller.rb
orders/
line_items_controller.rb
products_controller.rb
orders_controller.rb
This works fine in development but is failing on our AWS server with the below error:
{"method":"GET","path":"/api/","format":"html","controller":"ApplicationController","action":"main","status":200,"duration":5.03,"view":0.15,"db":1.46,"#timestamp":"2019-02-28T16:21:08Z","process_id":36,"ip":"10.41.143.0","owner_id":null,"owner_type":null,"params":{}}
ActionController::RoutingError (uninitialized constant Admin::Products::ProductsController):
activesupport (4.2.10) lib/active_support/inflector/methods.rb:263:in `const_get'
activesupport (4.2.10) lib/active_support/inflector/methods.rb:263:in `block in constantize'
activesupport (4.2.10) lib/active_support/inflector/methods.rb:259:in `each'
activesupport (4.2.10) lib/active_support/inflector/methods.rb:259:in `inject'
activesupport (4.2.10) lib/active_support/inflector/methods.rb:259:in `constantize'
actionpack (4.2.10) lib/action_dispatch/routing/route_set.rb:70:in `controller_reference'
actionpack (4.2.10) lib/action_dispatch/routing/route_set.rb:60:in `controller'
actionpack (4.2.10) lib/action_dispatch/routing/route_set.rb:39:in `serve'
actionpack (4.2.10) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.10) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.10) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.10) lib/action_dispatch/routing/route_set.rb:817:in `call'
rack (1.6.10) lib/rack/etag.rb:24:in `call'
rack (1.6.10) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.10) lib/rack/head.rb:13:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.10) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.10) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.10) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.10) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.10) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.10) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.10) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.10) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
rack-cors (1.0.2) lib/rack/cors.rb:97:in `call'
lograge (0.10.0) lib/lograge/rails_ext/rack/logger.rb:15:in `call_app'
railties (4.2.10) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.10) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.10) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.10) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.10) lib/rails/rack/logger.rb:20:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.10) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.10) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.10) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/static.rb:120:in `call'
rack (1.6.10) lib/rack/sendfile.rb:113:in `call'
ddtrace (0.8.0) lib/ddtrace/contrib/rack/middlewares.rb:89:in `call'
sentry-raven (2.7.4) lib/raven/integrations/rack.rb:51:in `call'
railties (4.2.10) lib/rails/engine.rb:518:in `call'
railties (4.2.10) lib/rails/application.rb:165:in `call'
rack (1.6.10) lib/rack/urlmap.rb:66:in `block in call'
rack (1.6.10) lib/rack/urlmap.rb:50:in `each'
rack (1.6.10) lib/rack/urlmap.rb:50:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
namespace :admin, shallow: true do
resources :products, module: 'products' do
resources :reviews
end
resources :orders, module: 'orders' do
resources :line_items
end
end
I'm not sure why it's looking for Admin::Products::ProductsController, because the products controller is under /app/controllers/admin/, not app/controllers/admin/products/.
Would really appreciate some help with this. I'm having trouble understanding why this is only occurring in production.
rake routes | grep 'products'
This is as much as I can share at the moment:
admin_products GET /admin/products(.:format) admin/products/products#index
POST /admin/products(.:format) admin/products/products#create
new_admin_products GET /admin/products/new(.:format) admin/products/products#new
edit_admin_products GET /admin/products/:id/edit(.:format) admin/products/products#edit
admin_product GET /admin/products/:id(.:format) admin/products/products#show
PATCH /admin/products/:id(.:format) admin/products/products#update
PUT /admin/products/:id(.:format) admin/products/products#update
DELETE /admin/products/:id(.:format) admin/products/products#destroy
The issue is that you are defining your module on the resources :products. You should define your module on the resources :reviews like this:
resources :products do
resources :reviews, module: 'products'
end
When you give a route a module, it will look inside ModuleName::ControllerName for the action(s).

Resources