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

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

Related

undefined method `keys' for nil:NilClass when calling gem method

I am trying to call a method from a gem that I have created but keep getting the error stated in the title. I've looked into the error but still dont know why it is occurring. When I run the file in the Command prompt it works perfectly. All I want to do it populate the method with user input and display the result in my index page. I am running the following it the command prompt:
irb -rubygems
require 'unit_converter'
UnitConverter::Weight.new.conversions(1, :kg)
The output changes depending on what I type in but for example the output for this would be:
["2.20462pounds", "0.157473stone"]
It's only when I try and link it up to my erb file that i get the error mentioned.
To reproduce the error This is the method I am creating in my measurements_controller file:
def unit_converter
#input1 = params[:value]
#input2 = params[:unit]
#result = UnitConverter::Weight.new.conversions(#input1.to_i , #input2)
end
And in my index.html.erb file I have a form like so:
<%= form_tag "/validate" do %>
<%= text_field_tag :value %>
<%= text_field_tag :unit %>
<%= submit_tag "Search" %>
<% end %>
<%= #result %>
And these are my routes to link everything up
get '/check', :controller=>'measurements', :action=>'index'
post '/validate', :controller=>'measurements', :action=>'unit_converter'
This is the gem that I am using and conversions is the method:
module UnitConverter
class ConversionError < StandardError
end
class Weight
# lookup table
CONVERSIONS = {
kg: {
pounds: 2.20462,
stone: 0.157473,
},
pounds: {
kg: 0.453592,
stone: 0.0714286
},
stone: {
kg: 6.35029,
pounds: 14
}
}
def convert(value, from, to:)
raise ConversionError, "Value is not numeric" unless value.is_a? Numeric
raise ConversionError, "Value #{value} is not positive" unless value >= 0
"#{value * conversion_ratio(from, to) }#{to.to_s}"
end
def conversions(value, unit)
CONVERSIONS[unit].keys.map do |other_unit|
convert(value, unit, to: other_unit)
end
end
private
def conversion_ratio(from, to)
begin
CONVERSIONS.fetch(from).fetch(to)
rescue KeyError
raise ConversionError, "Cannot convert #{from.to_s} to #{to.to_s}"
end
end
end
end
My full stack trace:
**unit_converter (0.0.0) lib/unit_converter.rb:32:in `conversions'
app/controllers/measurements_controller.rb:9:in `unit_converter'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.2.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
rack-pjax (1.1.0) lib/rack/pjax.rb:12:in `call'
remotipart (1.4.4) lib/remotipart/middleware.rb:32:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.2.2) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.2) lib/rack/etag.rb:27:in `call'
rack (2.2.2) lib/rack/conditional_get.rb:40:in `call'
rack (2.2.2) lib/rack/head.rb:12:in `call'
actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.2) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.2) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.2.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32: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.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.2.1) 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.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.2.1) 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.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.2.1) 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.2.1) lib/rails/engine.rb:526:in `call'
puma (4.3.1) lib/puma/configuration.rb:228:in `call'
puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
puma (4.3.1) lib/puma/server.rb:472:in `process_client'
puma (4.3.1) lib/puma/server.rb:328:in `block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'**
When you are calling the conversions method from the console, you are passing in a symbol :kg ... but when the method is being called in the controller, it's receiving a String.
So you just need to convert the unit of measure to a symbol, the same way you are converting the number value to an integer:
#result = UnitConverter::Weight.new.conversions(#input1.to_i , #input2.to_sym)
The error you got was b/c the lookup in your conversions table was essentially looking for Conversions['kg'] which returns nil -- hence the "undefined method keys..." error message.
Another solution, is to use a convenience method that Rails adds to the Hash class: with_indifferent_access.
If you define your lookup table like this (I'm omitting the guts of it), then you can access this Hash with either String keys or Symbol keys, and doing #input2.to_sym won't be necessary:
CONVERSIONS = {
...
}.with_indifferent_access

Edgeguides' Getting Started with Rails template missing error

I just began learning ruby on rails and while going through the guide link, I cannot change the page display in step 4.3
my routes.rb file looks precisely as recommended in the guide, having only two lines between the draw and its end:
get 'welcome/index'
root 'welcome#index'
while my index.html.erb file looks like this:
<h1>Hello, Rails!</h1>
yet when I load the localhost:3000 page, it gives the error
WelcomeController#index is missing a template for request formats:
text/html
even though the file index.html.erb is valid.
any suggestions for what could be the matter?
EDIT: Server log reads as follows:
Started GET "/welcome/index" for ::1 at 2020-02-12 15:19:39 -0500 (5.7ms) SELECT sqlite_version(*) Processing by WelcomeController#index as HTML Completed 406 Not Acceptable in 28ms (ActiveRecord: 0.0ms | Allocations: 1989)
ActionController::MissingExactTemplate (WelcomeController#index is missing a template for request formats: text/html):
actionpack (6.0.2.1) lib/action_controller/metal/implicit_render.rb:45:in `default_render'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.2.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
rack (2.2.2) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.2) lib/rack/etag.rb:27:in `call'
rack (2.2.2) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.2) lib/rack/head.rb:12:in `call'
actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.2) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.2) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.2.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32: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.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.2.1) 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.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.2.1) 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.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.2.1) 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.2.1) lib/rails/engine.rb:526:in `call'
puma (4.3.1) lib/puma/configuration.rb:228:in `call'
puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
puma (4.3.1) lib/puma/server.rb:472:in `process_client'
puma (4.3.1) lib/puma/server.rb:328:in `block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
I have also tried continuing to follow the guide to step 5.1 and though all the errors appear as the guide says, the 'solution' at the end of that step still causes an error with template format.

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).

raise ConnectionNotEstablished, "No connection pool with '#{spec_name}' found." unless pool LOCALHOST3000 not working

def retrieve_connection(spec_name) #:nodoc:
pool = retrieve_connection_pool(spec_name)
raise ConnectionNotEstablished, "No connection pool with '#{spec_name}' found." unless pool
pool.connection
end
I am working on a web app from scratch and found lots of errors in the ruby on rails code above. I installed all the gems required and install and connected home page in controller and route.rb but I can't find the solution for this problem.
activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:1009:in `retrieve_connection'
activerecord (5.2.2) lib/active_record/connection_handling.rb:118:in `retrieve_connection'
activerecord (5.2.2) lib/active_record/connection_handling.rb:90:in `connection'
activerecord (5.2.2) lib/active_record/migration.rb:554:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.2) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:61: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.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.2) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.2) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.2) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.6) lib/rack/method_override.rb:22:in `call'
rack (2.0.6) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.2) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
railties (5.2.2) lib/rails/engine.rb:524: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'
Check your database.yml file for invisible characters that might be throwing off the spacing. That'll produce the error you're referencing.

Ruby on Rails how do I create a has_one dependency on the creation of user

I am attempting to create an association between
class User
has_one :user_profile
end
class UserProfile
belongs_to :user
end
I want to create the ability to create the association when the user is created.
I have attempted things in the User Model like
before_create :build_profile
private
def build_profile
default_pararms = { some_key: value}
#profile = self.create_user_pofile!(default_params)
end
---- stack is returning ----
Redirected to http://localhost:3000/users
Completed 302 Found in 136ms (ActiveRecord: 0.3ms)
Started GET "/users" for 127.0.0.1 at 2018-03-31 01:56:40 -0400
ActionController::RoutingError (uninitialized constant UsersController):
activesupport (5.1.5) lib/active_support/inflector/methods.rb:269:in `const_get'
activesupport (5.1.5) lib/active_support/inflector/methods.rb:269:in `block in constantize'
activesupport (5.1.5) lib/active_support/inflector/methods.rb:267:in `each'
activesupport (5.1.5) lib/active_support/inflector/methods.rb:267:in `inject'
activesupport (5.1.5) lib/active_support/inflector/methods.rb:267:in `constantize'
actionpack (5.1.5) lib/action_dispatch/http/request.rb:85:in `controller_class_for'
actionpack (5.1.5) lib/action_dispatch/http/request.rb:78:in `controller_class'
actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:43:in `controller'
actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:29:in `serve'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.5) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.5) lib/action_dispatch/routing/route_set.rb:844:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.4) lib/rack/head.rb:12:in `call'
rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.5) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.5) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.5) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.5) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.5) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.5) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.5) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.5) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
railties (5.1.5) lib/rails/engine.rb:522:in `call'
puma (3.11.3) lib/puma/configuration.rb:225:in `call'
puma (3.11.3) lib/puma/server.rb:624:in `handle_request'
puma (3.11.3) lib/puma/server.rb:438:in `process_client'
puma (3.11.3) lib/puma/server.rb:302:in `block in run'
puma (3.11.3) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

Resources