I am building an embedded Shopify application on Rails 6.0.3.2 and using the most recent version of the mongoid gem to make use of MongoDB. I am also using the most recent version of the shopify_app gem.
gem 'mongoid', '7.1.4'
gem 'shopify_app', '15.0.0'
My issue arises when trying to access one of my own controllers via a POST request. In this specific instance, it is a create controller for creating orders via the Shopify::API.
I believe the error has something to do with the authenticating going on in the background for embedded apps.
This error only happens when the calling controller is inheriting from the AuthenticatedController. Which is a controller generated by the shopify_app gem and required for authentication purposes, and that is required to make use of the Shopify::API inside of an embedded app.. If I simply change to < ApplicationController
The error goes away. This error happens without actually trying to access Mongo from the controller, even when calling an empty controller, though only one accessed by a POST request, controllers accessed via GET requests work fine. I even have one controller that has a working create action when inheriting from ApplicationController that breaks as soon as it inherits from AuthenticatedController. This is why I believe it has to do with background authentication between the embedded_app and the store.
This error can be seen below
Mongo::Error::OperationFailure in OrderFulfillmentsController#update_orders
unknown operator: $oid (2) (on localhost:27017, modern retry, attempt 1)
Application Trace | Framework Trace | Full Trace
mongo (2.13.1) lib/mongo/operation/result.rb:321:in raise_operation_failure' mongo (2.13.1) lib/mongo/operation/result.rb:289:in validate!'
mongo (2.13.1) lib/mongo/operation/shared/response_handling.rb:29:in block (3 levels) in validate_result' mongo (2.13.1) lib/mongo/operation/shared/response_handling.rb:96:in add_server_diagnostics'
mongo (2.13.1) lib/mongo/operation/shared/response_handling.rb:28:in block (2 levels) in validate_result' mongo (2.13.1) lib/mongo/operation/shared/response_handling.rb:43:in add_error_labels'
mongo (2.13.1) lib/mongo/operation/shared/response_handling.rb:27:in block in validate_result' mongo (2.13.1) lib/mongo/operation/shared/response_handling.rb:82:in unpin_maybe'
mongo (2.13.1) lib/mongo/operation/shared/response_handling.rb:26:in validate_result' mongo (2.13.1) lib/mongo/operation/shared/executable.rb:45:in block in execute'
mongo (2.13.1) lib/mongo/operation/shared/executable.rb:44:in tap' mongo (2.13.1) lib/mongo/operation/shared/executable.rb:44:in execute'
mongo (2.13.1) lib/mongo/operation/shared/op_msg_or_find_command.rb:29:in block in execute' mongo (2.13.1) lib/mongo/server/connection_pool.rb:590:in with_connection'
mongo (2.13.1) lib/mongo/server.rb:425:in with_connection' mongo (2.13.1) lib/mongo/operation/shared/op_msg_or_find_command.rb:27:in execute'
mongo (2.13.1) lib/mongo/collection/view/iterable.rb:104:in send_initial_query' mongo (2.13.1) lib/mongo/collection/view/iterable.rb:46:in block in each'
mongo (2.13.1) lib/mongo/retryable.rb:61:in block in read_with_retry_cursor' mongo (2.13.1) lib/mongo/retryable.rb:316:in modern_read_with_retry'
mongo (2.13.1) lib/mongo/retryable.rb:117:in read_with_retry' mongo (2.13.1) lib/mongo/retryable.rb:60:in read_with_retry_cursor'
/usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/forwardable.rb:235:in read_with_retry_cursor' mongo (2.13.1) lib/mongo/collection/view/iterable.rb:45:in each'
mongoid (7.1.4) lib/mongoid/query_cache.rb:228:in each' mongoid (7.1.4) lib/mongoid/contextual/mongo.rb:282:in first'
mongoid (7.1.4) lib/mongoid/contextual/mongo.rb:282:in find_first' /usr/share/rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/forwardable.rb:235:in find_first'
mongoid (7.1.4) lib/mongoid/findable.rb:119:in find_by' shopify_app (15.0.0) lib/shopify_app/session/shop_session_storage.rb:20:in retrieve'
shopify_app (15.0.0) lib/shopify_app/session/session_repository.rb:12:in retrieve_shop_session' shopify_app (15.0.0) lib/shopify_app/controller_concerns/login_protection.rb:76:in shop_session_by_cookie'
shopify_app (15.0.0) lib/shopify_app/controller_concerns/login_protection.rb:65:in shop_session' shopify_app (15.0.0) lib/shopify_app/controller_concerns/login_protection.rb:45:in current_shopify_session'
shopify_app (15.0.0) lib/shopify_app/controller_concerns/login_protection.rb:89:in login_again_if_different_user_or_shop' activesupport (6.0.3.4) lib/active_support/callbacks.rb:428:in block in make_lambda'
activesupport (6.0.3.4) lib/active_support/callbacks.rb:200:in block (2 levels) in halting' actionpack (6.0.3.4) lib/abstract_controller/callbacks.rb:34:in block (2 levels) in module:Callbacks'
activesupport (6.0.3.4) lib/active_support/callbacks.rb:201:in block in halting' activesupport (6.0.3.4) lib/active_support/callbacks.rb:513:in block in invoke_before'
activesupport (6.0.3.4) lib/active_support/callbacks.rb:513:in each' activesupport (6.0.3.4) lib/active_support/callbacks.rb:513:in invoke_before'
activesupport (6.0.3.4) lib/active_support/callbacks.rb:110:in block in run_callbacks' activesupport (6.0.3.4) lib/active_support/callbacks.rb:139:in run_callbacks'
actionpack (6.0.3.4) lib/abstract_controller/callbacks.rb:41:in process_action' actionpack (6.0.3.4) lib/action_controller/metal/rescue.rb:22:in process_action'
actionpack (6.0.3.4) lib/action_controller/metal/instrumentation.rb:33:in block in process_action' activesupport (6.0.3.4) lib/active_support/notifications.rb:180:in block in instrument'
activesupport (6.0.3.4) lib/active_support/notifications/instrumenter.rb:24:in instrument' activesupport (6.0.3.4) lib/active_support/notifications.rb:180:in instrument'
actionpack (6.0.3.4) lib/action_controller/metal/instrumentation.rb:32:in process_action' actionpack (6.0.3.4) lib/action_controller/metal/params_wrapper.rb:245:in process_action'
mongoid (7.1.4) lib/mongoid/railties/controller_runtime.rb:22:in process_action' actionpack (6.0.3.4) lib/abstract_controller/base.rb:136:in process'
actionview (6.0.3.4) lib/action_view/rendering.rb:39:in process' actionpack (6.0.3.4) lib/action_controller/metal.rb:190:in dispatch'
actionpack (6.0.3.4) lib/action_controller/metal.rb:254:in dispatch' actionpack (6.0.3.4) lib/action_dispatch/routing/route_set.rb:50:in dispatch'
actionpack (6.0.3.4) lib/action_dispatch/routing/route_set.rb:33:in serve' actionpack (6.0.3.4) lib/action_dispatch/journey/router.rb:49:in block in serve'
actionpack (6.0.3.4) lib/action_dispatch/journey/router.rb:32:in each' actionpack (6.0.3.4) lib/action_dispatch/journey/router.rb:32:in serve'
actionpack (6.0.3.4) lib/action_dispatch/routing/route_set.rb:834:in call' omniauth (1.9.1) lib/omniauth/strategy.rb:192:in call!'
omniauth (1.9.1) lib/omniauth/strategy.rb:169:in call' omniauth (1.9.1) lib/omniauth/builder.rb:45:in call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in call' rack (2.2.3) lib/rack/etag.rb:27:in call'
rack (2.2.3) lib/rack/conditional_get.rb:40:in call' rack (2.2.3) lib/rack/head.rb:12:in call'
actionpack (6.0.3.4) lib/action_dispatch/http/content_security_policy.rb:18:in call' rack (2.2.3) lib/rack/session/abstract/id.rb:266:in context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in call' actionpack (6.0.3.4) lib/action_dispatch/middleware/cookies.rb:648:in call'
actionpack (6.0.3.4) lib/action_dispatch/middleware/callbacks.rb:27:in block in call' activesupport (6.0.3.4) lib/active_support/callbacks.rb:101:in run_callbacks'
actionpack (6.0.3.4) lib/action_dispatch/middleware/callbacks.rb:26: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/actionable_exceptions.rb:18:in call' actionpack (6.0.3.4) lib/action_dispatch/middleware/debug_exceptions.rb:32: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:19: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:11: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'
This can be solved by defining the following method on your Shop class. Located at Shop.rb
def id
_id.to_s
end
I believe this is due to the fact that MongoDB defines _ids as a BSON object by default, but the authentication workflow is looking for a string.
Related
I have a simple Ruby on Rails repo, and I found that if I specified the homepage as index in Roues, it would throw a "" error. I can't find any spelling mistakes:
This is Route
Rails.application.routes.draw do
resources :foos
root "foos#index"
end
This is the part of the Controller
class FoosController < ApplicationController
before_action :find_foo, only: [:edit, :update, :destroy]
def index
#foos = Foo.all
end
My View file is app/views/index.html.erb
This is logs:
ActionController::MissingExactTemplate (FoosController#index is missing a template for request formats: text/html):
actionpack (7.0.2.2) lib/action_controller/metal/implicit_render.rb:45:in default_render' actionpack (7.0.2.2) lib/action_controller/metal/basic_implicit_render.rb:6:in block in send_action'
actionpack (7.0.2.2) lib/action_controller/metal/basic_implicit_render.rb:6:in tap' actionpack (7.0.2.2) lib/action_controller/metal/basic_implicit_render.rb:6:in send_action'
actionpack (7.0.2.2) lib/abstract_controller/base.rb:214:in process_action' actionpack (7.0.2.2) lib/action_controller/metal/rendering.rb:53:in process_action'
actionpack (7.0.2.2) lib/abstract_controller/callbacks.rb:234:in block in process_action' activesupport (7.0.2.2) lib/active_support/callbacks.rb:118:in block in run_callbacks'
actiontext (7.0.2.2) lib/action_text/rendering.rb:20:in with_renderer' actiontext (7.0.2.2) lib/action_text/engine.rb:69:in block (4 levels) in class:Engine'
activesupport (7.0.2.2) lib/active_support/callbacks.rb:127:in instance_exec' activesupport (7.0.2.2) lib/active_support/callbacks.rb:127:in block in run_callbacks'
activesupport (7.0.2.2) lib/active_support/callbacks.rb:138:in run_callbacks' actionpack (7.0.2.2) lib/abstract_controller/callbacks.rb:233:in process_action'
actionpack (7.0.2.2) lib/action_controller/metal/rescue.rb:22:in process_action' actionpack (7.0.2.2) lib/action_controller/metal/instrumentation.rb:67:in block in process_action'
activesupport (7.0.2.2) lib/active_support/notifications.rb:206:in block in instrument' activesupport (7.0.2.2) lib/active_support/notifications/instrumenter.rb:24:in instrument'
activesupport (7.0.2.2) lib/active_support/notifications.rb:206:in instrument' actionpack (7.0.2.2) lib/action_controller/metal/instrumentation.rb:66:in process_action'
actionpack (7.0.2.2) lib/action_controller/metal/params_wrapper.rb:259:in process_action' activerecord (7.0.2.2) lib/active_record/railties/controller_runtime.rb:27:in process_action'
actionpack (7.0.2.2) lib/abstract_controller/base.rb:151:in process' actionview (7.0.2.2) lib/action_view/rendering.rb:39:in process'
actionpack (7.0.2.2) lib/action_controller/metal.rb:188:in dispatch' actionpack (7.0.2.2) lib/action_controller/metal.rb:251:in dispatch'
actionpack (7.0.2.2) lib/action_dispatch/routing/route_set.rb:49:in dispatch' actionpack (7.0.2.2) lib/action_dispatch/routing/route_set.rb:32:in serve'
actionpack (7.0.2.2) lib/action_dispatch/journey/router.rb:50:in block in serve' actionpack (7.0.2.2) lib/action_dispatch/journey/router.rb:32:in each'
actionpack (7.0.2.2) lib/action_dispatch/journey/router.rb:32:in serve' actionpack (7.0.2.2) lib/action_dispatch/routing/route_set.rb:850:in call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in call' rack (2.2.3) lib/rack/etag.rb:27:in call'
rack (2.2.3) lib/rack/conditional_get.rb:27:in call' rack (2.2.3) lib/rack/head.rb:12:in call'
actionpack (7.0.2.2) lib/action_dispatch/http/permissions_policy.rb:22:in call' actionpack (7.0.2.2) lib/action_dispatch/http/content_security_policy.rb:18:in call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in context' rack (2.2.3) lib/rack/session/abstract/id.rb:260:in call'
actionpack (7.0.2.2) lib/action_dispatch/middleware/cookies.rb:693:in call' activerecord (7.0.2.2) lib/active_record/migration.rb:603:in call'
actionpack (7.0.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in block in call' activesupport (7.0.2.2) lib/active_support/callbacks.rb:99:in run_callbacks'
actionpack (7.0.2.2) lib/action_dispatch/middleware/callbacks.rb:26:in call' actionpack (7.0.2.2) lib/action_dispatch/middleware/executor.rb:14:in call'
actionpack (7.0.2.2) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in call' actionpack (7.0.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:28:in call'
web-console (4.2.0) lib/web_console/middleware.rb:132:in call_app' web-console (4.2.0) lib/web_console/middleware.rb:28:in block in call'
web-console (4.2.0) lib/web_console/middleware.rb:17:in catch' web-console (4.2.0) lib/web_console/middleware.rb:17:in call'
actionpack (7.0.2.2) lib/action_dispatch/middleware/show_exceptions.rb:26:in call' railties (7.0.2.2) lib/rails/rack/logger.rb:36:in call_app'
railties (7.0.2.2) lib/rails/rack/logger.rb:25:in block in call' activesupport (7.0.2.2) lib/active_support/tagged_logging.rb:99:in block in tagged'
activesupport (7.0.2.2) lib/active_support/tagged_logging.rb:37:in tagged' activesupport (7.0.2.2) lib/active_support/tagged_logging.rb:99:in tagged'
railties (7.0.2.2) lib/rails/rack/logger.rb:25:in call' sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in call'
actionpack (7.0.2.2) lib/action_dispatch/middleware/remote_ip.rb:93:in call' actionpack (7.0.2.2) lib/action_dispatch/middleware/request_id.rb:26:in call'
rack (2.2.3) lib/rack/method_override.rb:24:in call' rack (2.2.3) lib/rack/runtime.rb:22:in call'
activesupport (7.0.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in call' actionpack (7.0.2.2) lib/action_dispatch/middleware/server_timing.rb:20:in call'
actionpack (7.0.2.2) lib/action_dispatch/middleware/executor.rb:14:in call' actionpack (7.0.2.2) lib/action_dispatch/middleware/static.rb:23:in call'
rack (2.2.3) lib/rack/sendfile.rb:110:in call' actionpack (7.0.2.2) lib/action_dispatch/middleware/host_authorization.rb:137:in call'
railties (7.0.2.2) lib/rails/engine.rb:530:in call' puma (5.6.2) lib/puma/configuration.rb:252:in call'
puma (5.6.2) lib/puma/request.rb:77:in block in handle_request' puma (5.6.2) lib/puma/thread_pool.rb:340:in with_force_shutdown'
puma (5.6.2) lib/puma/request.rb:76:in handle_request' puma (5.6.2) lib/puma/server.rb:441:in process_client'
puma (5.6.2) lib/puma/thread_pool.rb:147:in `block in spawn_thread'
What am I missing?
My View file is app/views/index.html.erb
This is the issue. Your view file should be present at app/views/foos/index.html.erb
Rails will automatically render a view that matches the name of the controller and action. Convention Over Configuration! Views are located in the app/views directory. So the index action will render app/views/foos/index.html.erb by default.
You can read more on this official Rails page.
I am getting this error when I try to sign up a user. After this error, I'm still able to sign in with the user it would've created, but it always shows me this upon registration. Please let me know if there's other information you need. Been stumped on this for a few days.
Here is the exception causes:
Here is the callback for the error:
actionpack (7.0.0) lib/action_dispatch/routing/polymorphic_routes.rb:231:in `public_send'
actionpack (7.0.0) lib/action_dispatch/routing/polymorphic_routes.rb:231:in `polymorphic_method'
actionpack (7.0.0) lib/action_dispatch/routing/polymorphic_routes.rb:116:in `polymorphic_url'
actionpack (7.0.0) lib/action_dispatch/routing/url_for.rb:187:in `full_url_for'
actionpack (7.0.0) lib/action_dispatch/routing/url_for.rb:170:in `url_for'
actionpack (7.0.0) lib/action_controller/metal/redirecting.rb:144:in `_compute_redirect_to_location'
actionpack (7.0.0) lib/action_controller/metal/redirecting.rb:89:in `redirect_to'
actionpack (7.0.0) lib/action_controller/metal/flash.rb:62:in `redirect_to'
actionpack (7.0.0) lib/action_controller/metal/instrumentation.rb:42:in `block in redirect_to'
activesupport (7.0.0) lib/active_support/notifications.rb:206:in `block in instrument'
activesupport (7.0.0) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (7.0.0) lib/active_support/notifications.rb:206:in `instrument'
actionpack (7.0.0) lib/action_controller/metal/instrumentation.rb:41:in `redirect_to'
responders (3.0.1) lib/action_controller/responder.rb:147:in `redirect_to'
responders (3.0.1) lib/action_controller/responder.rb:207:in `navigation_behavior'
responders (3.0.1) lib/action_controller/responder.rb:174:in `rescue in to_html'
responders (3.0.1) lib/action_controller/responder.rb:171:in `to_html'
responders (3.0.1) lib/action_controller/responder.rb:165:in `respond'
responders (3.0.1) lib/action_controller/responder.rb:158:in `call'
responders (3.0.1) lib/action_controller/respond_with.rb:213:in `respond_with'
devise (4.8.1) app/controllers/devise/registrations_controller.rb:25:in `create'
actionpack (7.0.0) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (7.0.0) lib/abstract_controller/base.rb:214:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/rendering.rb:53:in `process_action'
actionpack (7.0.0) lib/abstract_controller/callbacks.rb:234:in `block in process_action'
activesupport (7.0.0) lib/active_support/callbacks.rb:118:in `block in run_callbacks'
actiontext (7.0.0) lib/action_text/rendering.rb:20:in `with_renderer'
actiontext (7.0.0) lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'
activesupport (7.0.0) lib/active_support/callbacks.rb:127:in `instance_exec'
activesupport (7.0.0) lib/active_support/callbacks.rb:127:in `block in run_callbacks'
activesupport (7.0.0) lib/active_support/callbacks.rb:138:in `run_callbacks'
actionpack (7.0.0) lib/abstract_controller/callbacks.rb:233:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'
activesupport (7.0.0) lib/active_support/notifications.rb:206:in `block in instrument'
activesupport (7.0.0) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (7.0.0) lib/active_support/notifications.rb:206:in `instrument'
actionpack (7.0.0) lib/action_controller/metal/instrumentation.rb:66:in `process_action'
actionpack (7.0.0) lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
activerecord (7.0.0) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (7.0.0) lib/abstract_controller/base.rb:151:in `process'
actionview (7.0.0) lib/action_view/rendering.rb:39:in `process'
actionpack (7.0.0) lib/action_controller/metal.rb:188:in `dispatch'
actionpack (7.0.0) lib/action_controller/metal.rb:251:in `dispatch'
actionpack (7.0.0) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (7.0.0) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (7.0.0) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
actionpack (7.0.0) lib/action_dispatch/routing/mapper.rb:48:in `serve'
actionpack (7.0.0) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (7.0.0) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (7.0.0) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (7.0.0) lib/action_dispatch/routing/route_set.rb:850:in `call'
warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
warden (1.2.9) lib/warden/manager.rb:34:in `catch'
warden (1.2.9) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
actionpack (7.0.0) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
actionpack (7.0.0) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/cookies.rb:693:in `call'
activerecord (7.0.0) lib/active_record/migration.rb:603:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (7.0.0) lib/active_support/callbacks.rb:99:in `run_callbacks'
actionpack (7.0.0) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call'
web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/show_exceptions.rb:26:in `call'
railties (7.0.0) lib/rails/rack/logger.rb:36:in `call_app'
railties (7.0.0) lib/rails/rack/logger.rb:25:in `block in call'
activesupport (7.0.0) lib/active_support/tagged_logging.rb:99:in `block in tagged'
activesupport (7.0.0) lib/active_support/tagged_logging.rb:37:in `tagged'
activesupport (7.0.0) lib/active_support/tagged_logging.rb:99:in `tagged'
railties (7.0.0) lib/rails/rack/logger.rb:25:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/remote_ip.rb:93:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/request_id.rb:26:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (7.0.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/server_timing.rb:20:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/static.rb:23:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (7.0.0) lib/action_dispatch/middleware/host_authorization.rb:137:in `call'
railties (7.0.0) lib/rails/engine.rb:530:in `call'
puma (5.5.2) lib/puma/configuration.rb:249:in `call'
puma (5.5.2) lib/puma/request.rb:77:in `block in handle_request'
puma (5.5.2) lib/puma/thread_pool.rb:340:in `with_force_shutdown'
puma (5.5.2) lib/puma/request.rb:76:in `handle_request'
puma (5.5.2) lib/puma/server.rb:447:in `process_client'
puma (5.5.2) lib/puma/thread_pool.rb:147:in `block in spawn_thread'
My routes.rb:
Rails.application.routes.draw do
devise_for :users
resources :teachers
resources :offices
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
root to: "offices#index"
# root "articles#index"
end
This seems to a be a known issue with Rails 7 and Devise now. To fix it in the meantime simply add the following line to your devise.rb.
config.navigational_formats = ['*/*', :html, :turbo_stream]
Source:
https://github.com/heartcombo/devise/issues/5439
I am working on running a Rails application in production. It's still a proof of concept, but I'm running into ActionController::InvalidAuthenticityToken exceptions for form submissions. My understanding is that in Rails 6 (or maybe earlier?) the protect_from_forgery callback is now called by default. To get it to work, I added the configuration option config.action_controller.allow_forgery_protection = false in my config/environments/production.rb file, and now I'm working on re-enabling forgery protection so I removed the override and attempted to submit some forms (or log out, basically anything that uses a POST/PUT/PATCH/DELETE method).
My ApplicationController does not call protect_from_forgery manually, and all GET requests appear to be working just fine. My application.html.haml includes the following within %head:
= csrf_meta_tags
= csp_meta_tag
My forms are using bootstrap_form_with and the form is submitting an authenticity_token form parameter that matches what is in the %head (verified from Chrome dev tools and the logs). When I submit, I see that the response is a 422 error with the exception in the logs:
[3d603471-3240-4401-a3a2-e9ba3c6ac358] ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
[3d603471-3240-4401-a3a2-e9ba3c6ac358]
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal/request_forgery_protection.rb:217:in `handle_unverified_request'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal/request_forgery_protection.rb:249:in `handle_unverified_request'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] devise (4.7.1) lib/devise/controllers/helpers.rb:255:in `handle_unverified_request'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal/request_forgery_protection.rb:244:in `verify_authenticity_token'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:429:in `block in make_lambda'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:201:in `block (2 levels) in halting'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:202:in `block in halting'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:514:in `block in invoke_before'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:514:in `each'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:514:in `invoke_before'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:110:in `block in run_callbacks'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] ahoy_matey (3.0.1) lib/ahoy/controller.rb:45:in `set_ahoy_request_store'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:121:in `block in run_callbacks'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:139:in `run_callbacks'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in `process'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionview (6.0.2.1) lib/action_view/rendering.rb:39:in `process'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in `dispatch'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in `dispatch'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/routing/mapper.rb:48:in `serve'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `each'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `serve'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] warden (1.2.8) lib/warden/manager.rb:34:in `catch'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] warden (1.2.8) lib/warden/manager.rb:34:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/tempfile_reaper.rb:15:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/etag.rb:25:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/conditional_get.rb:38:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/head.rb:12:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/session/abstract/id.rb:259:in `context'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/session/abstract/id.rb:253:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] turbolinks_render (0.9.17) lib/turbolinks_render/middleware.rb:77:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] ahoy_matey (3.0.1) lib/ahoy/engine.rb:22:in `call_with_quiet_ahoy'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] request_store (1.5.0) lib/request_store/middleware.rb:19:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/method_override.rb:22:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/runtime.rb:22:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] rack (2.0.8) lib/rack/sendfile.rb:111:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:77:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] railties (6.0.2.1) lib/rails/engine.rb:526:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] puma (4.3.1) lib/puma/configuration.rb:228:in `call'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] puma (4.3.1) lib/puma/server.rb:472:in `process_client'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] puma (4.3.1) lib/puma/server.rb:328:in `block in run'
[3d603471-3240-4401-a3a2-e9ba3c6ac358] puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
I saw that devise recommended that I use prepend on the forgery protection, so I added the following to the ApplicationController:
protect_from_forgery with: :exception, prepend: true
I'm a bit stumped as to why this is happening, and can certainly provide some more code samples, but I'm not entirely sure what is necessary.
Thanks so much
In my case, solving this involved enabling the option in config/environments/production.rb as shown:
config.force_ssl = true
I'm not sure if this is the only thing, unfortunately, since it was a while since I asked the question, however, after I enabled it request forgery protection started working.
I keep bumping into exception errors that I believe are due to conflicts from reserved keywords.
For example, I have a permit model with the attribute "gross_value" When my view tries to retrieve #permit.gross_value I get the following exception error. However, when I rename the attribute to #permit.value_gross (without changing anything else) the view works fine. I've had similar issues with other attribute names.
Is my diagnosis of the reason for the exception correct? How do I know what keywords to avoid this issue?
UPDATE: In the console when I try to access the attribute "total_weight" from the "permit" model e.g. "Permit.first.total_weight" I get a "stack level too deep" error message. When I rename the attribute from "total_weight" to "total_weigh" it works fine e.g. "Permit.first.total_weigh".
After renaming the attribute I still get the stack level too deep error message when trying to access "Permit.first.total_weight", which is curious because now the attribute does not exist so I expect to get a "undefined method" error as I do with other models e.g. "User.first.total_weight."
For now I am fine to make do with renaming my attribute to "total_weigh" - this has resolved the issue and everything is running smoothly. I'm just curious as to the reasoning and whether my diagnosis of a reserved keyword conflict is correct?
fatal (exception reentered):
actionpack (5.0.1) lib/action_controller/metal/rescue.rb:23:in `rescue in process_action'
actionpack (5.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.1) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.1) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.1) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.1) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.1) lib/active_record/migration.rb:553:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
web-console (3.1.1) lib/web_console/middleware.rb:131:in `call_app'
web-console (3.1.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.1.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.1.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.1) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.1) lib/rails/engine.rb:522:in `call'
puma (3.4.0) lib/puma/configuration.rb:224:in `call'
puma (3.4.0) lib/puma/server.rb:569:in `handle_request'
puma (3.4.0) lib/puma/server.rb:406:in `process_client'
puma (3.4.0) lib/puma/server.rb:271:in `block in run'
puma (3.4.0) lib/puma/thread_pool.rb:114:in `block in spawn_thread'
Thanks for your help!
Simon
Are you doing any recursive calls in your code? This error usually means that you have re-entered a recursive call in your code.
Check your callbacks(i.e. before_save, before_validation etc.), if you have any, as these are common places where this can occur.
I am using ActiveAdmin (with customized gemset for Rails 4) with Rails 4.0.0.rc2. Application also has custom-built authorization code based on railscasts #385 and #386.
When I change something in a ActiveAdmin resource file and try to refresh the browser page, I get this error at the current_permission method:
ArgumentError at /admin/courses
A copy of ApplicationController has been removed from the module tree but is still active!
If I try a refresh again, I get:
Circular dependency detected while autoloading constant Permissions
I think this problem has something to do with autoloading of classes in development mode, after a change in the source file. I have seen similar problem posts, but they are for rails 2.3.x. Also, the solution seems to be specifying unloadable in the controller throwing this error, but I am not sure where to put in this snippet in ActiveAdmin.
This might not have anything to do with ActiveAdmin either. It might be about how Permissions class has been built and its usage within Application Controller. If I add a skip_before_filter :authorize in the ActiveAdmin resource class, this error vanishes.
ApplicationController:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :authenticate_user!
before_filter :authorize
delegate :allow_action?, to: :current_permission
helper_method :allow_action?
delegate :allow_param?, to: :current_permission
helper_method :allow_param?
private
def current_permission
#current_permission ||= Permissions.permission_for(current_user)
end
def current_resource
nil
end
def authorize
if current_permission.allow_action?(params[:controller], params[:action], current_resource)
current_permission.permit_params! params
else
redirect_to root_url, alert: "Not authorized."
end
end
end
Permissions.rb:
module Permissions
def self.permission_for(user)
if user.nil?
GuestPermission.new
elsif user.admin?
AdminPermission.new(user)
else
UserPermission.new(user)
end
end
end
admin/courses.rb:
ActiveAdmin.register Course do
index do
column :name
column :description
column :duration
column :status
column :price
default_actions
end
filter :discipline
filter :level
filter :lessons
filter :name
filter :status
end
Gemfile (relevant lines):
gem 'rails', '4.0.0.rc2'
# Use puma as the app server
gem 'puma'
# Administration - Temporary github refs until rails 4 compatible releases
gem 'responders', github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack', github: 'ernie/ransack', branch: 'rails-4'
gem 'activeadmin', github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic', github: 'justinfrench/formtastic'
ArgumentError:
ArgumentError - A copy of ApplicationController has been removed from the module tree but is still active!:
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:445:in `load_missing_constant'
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:183:in `const_missing'
rspec-core (2.13.1) lib/rspec/core/backward_compatibility.rb:24:in `const_missing'
app/controllers/application_controller.rb:17:in `current_permission'
app/controllers/application_controller.rb:25:in `authorize'
activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:417:in `_run__1040990970961152968__process_action__callbacks'
activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0.rc2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0.rc2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0.rc2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0.rc2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0.rc2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0.rc2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0.rc2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0.rc2) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0.rc2) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0.rc2) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0.rc2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0.rc2) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0.rc2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0.rc2) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0.rc2) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/routing/route_set.rb:655:in `call'
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/error_collector.rb:12:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/agent_hooks.rb:22:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/browser_monitoring.rb:16:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/developer_mode.rb:28:in `call'
meta_request (0.2.7) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
meta_request (0.2.7) lib/meta_request/middlewares/headers.rb:16:in `call'
meta_request (0.2.7) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0.rc2) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0.rc2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0.rc2) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:373:in `_run__2183739952227501342__call__callbacks'
activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0.rc2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0.rc2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0.rc2) lib/rails/engine.rb:511:in `call'
railties (4.0.0.rc2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
puma (2.1.1) lib/puma/server.rb:369:in `handle_request'
puma (2.1.1) lib/puma/server.rb:246:in `process_client'
puma (2.1.1) lib/puma/server.rb:145:in `block in run'
puma (2.1.1) lib/puma/thread_pool.rb:92:in `block in spawn_thread'
RuntimeError: Circular Dependency:
RuntimeError - Circular dependency detected while autoloading constant Permissions:
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:460:in `load_missing_constant'
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:183:in `const_missing'
rspec-core (2.13.1) lib/rspec/core/backward_compatibility.rb:24:in `const_missing'
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:686:in `remove_constant'
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:516:in `block in remove_unloadable_constants!'
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:516:in `remove_unloadable_constants!'
activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:300:in `clear'
railties (4.0.0.rc2) lib/rails/application/finisher.rb:90:in `block (2 levels) in <module:Finisher>'
activesupport (4.0.0.rc2) lib/active_support/file_update_checker.rb:75:in `execute'
railties (4.0.0.rc2) lib/rails/application/finisher.rb:105:in `block (2 levels) in <module:Finisher>'
activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:377:in `_run__2753119820186226816__prepare__callbacks'
activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/reloader.rb:62:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0.rc2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0.rc2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0.rc2) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0.rc2) lib/rails/engine.rb:511:in `call'
railties (4.0.0.rc2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
puma (2.1.1) lib/puma/server.rb:369:in `handle_request'
puma (2.1.1) lib/puma/server.rb:246:in `process_client'
puma (2.1.1) lib/puma/server.rb:145:in `block in run'
puma (2.1.1) lib/puma/thread_pool.rb:92:in `block in spawn_thread'
Any clue will help.
Let me know if you need to view other code snippets in the application.
For future visitors, I thought I'd provide some clarification on the original problem even though the question is pretty old and there is already an accepted answer.
The ArgumentError: A copy of X has been removed from the module tree but is still active is raised when you are trying to access an automatically reloaded class (in app directory) from one that is not automatically reloaded (in lib directory).
I'm not sure exactly why this is happening, but I found a workaound. Change this:
def current_permission
#current_permission ||= Permissions.permission_for(current_user)
end
To this:
def current_permission
#current_permission ||= ::Permissions.permission_for(current_user)
end
The error is raised at this point in ActiveSupport:
# Load the constant named +const_name+ which is missing from +from_mod+. If
# it is not possible to load the constant into from_mod, try its parent
# module using +const_missing+.
def load_missing_constant(from_mod, const_name)
log_call from_mod, const_name
unless qualified_const_defined?(from_mod.name) && Inflector.constantize(from_mod.name).equal?(from_mod)
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
end
# ...
end
The problem only occurs when you don't fully qualify the constant name, so Rails tries looking it up in the ApplicationController namespace.
In you development.rb temporarily try putting
config.cache_classes = true
It worked for me.
I am not using ActiveAdmin, but I just experienced a circular dependency with ApplicationController.
The problem was a helper module was declared improperly:
app/helpers/home_helper.rb
was declared with:
module StaticHelper
After fixing this, everything was peachy. I did not research why this happened and Rails didn't return a more intelligent error message.
You can try put this line in your config/initializers/active_admin.rb:
In Rails <= 4:
config.skip_before_filter :load_footer_variables
In Rails >= 5
config.skip_before_action :load_footer_variables
Like suggested here.
If you have this problem in console, simply close console instead of reload! command as this happens due to automatically reloaded modules being run inside console without being fully reloaded.