foodsoft icon indicating copy to clipboard operation
foodsoft copied to clipboard

mailer cannot find (route) scope :foodcoop

Open carchrae opened this issue 5 years ago • 7 comments

i've been bashing my head off this. at first, i thought it was some change i had made, but i've checked out what i think is a clean version and the same problem persists.

using sqllite, to reproduce, go to forget password screen, and enter [email protected].

Mailer#reset_password: processed outbound mail in 1.3ms
Completed 500 Internal Server Error in 69ms (ActiveRecord: 6.7ms)

ActionController::UrlGenerationError (No route matches {:action=>"new_password", :controller=>"login", :id=>1, :token=>"ntytroslyslulicruquephystiragemifrybidohi"} missing required keys: [:foodcoop]):
  app/mailers/mailer.rb:19:in `reset_password'
  app/models/user.rb:135:in `request_password_reset!'
  app/controllers/login_controller.rb:18:in `reset_password'
  app/controllers/application_controller.rb:93:in `set_currency'
  app/controllers/application_controller.rb:81:in `set_time_zone'



ActionController::UrlGenerationError: No route matches {:action=>"new_password", :controller=>"login", :id=>1, :token=>"ntytroslyslulicruquephystiragemifrybidohi"} missing required keys: [:foodcoop]
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/journey/formatter.rb:46:in `generate'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:721:in `generate'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:752:in `generate'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:799:in `url_for'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:280:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:223:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:345:in `block (2 levels) in define_url_helper'
	from /home/tom/projects/food/clean/foodsoft/app/mailers/mailer.rb:19:in `reset_password'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/base.rb:198:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/callbacks.rb:19:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/base.rb:137:in `process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionview-4.2.11/lib/action_view/rendering.rb:30:in `process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionmailer-4.2.11/lib/action_mailer/base.rb:596:in `block in process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/notifications.rb:164:in `block in instrument'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/notifications.rb:164:in `instrument'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionmailer-4.2.11/lib/action_mailer/base.rb:593:in `process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionmailer-4.2.11/lib/action_mailer/base.rb:584:in `initialize'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionmailer-4.2.11/lib/action_mailer/message_delivery.rb:25:in `new'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionmailer-4.2.11/lib/action_mailer/message_delivery.rb:25:in `__getobj__'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionmailer-4.2.11/lib/action_mailer/message_delivery.rb:34:in `message'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionmailer-4.2.11/lib/action_mailer/message_delivery.rb:85:in `deliver_now'
	from /home/tom/projects/food/clean/foodsoft/app/models/user.rb:135:in `request_password_reset!'
	from /home/tom/projects/food/clean/foodsoft/app/controllers/login_controller.rb:18:in `reset_password'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/base.rb:198:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal/rendering.rb:10:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:117:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:505:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:313:in `block (2 levels) in halting'
	from /home/tom/projects/food/clean/foodsoft/app/controllers/application_controller.rb:93:in `set_currency'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:432:in `block in make_lambda'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:312:in `block in halting'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:497:in `block in around'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:505:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:313:in `block (2 levels) in halting'
	from /home/tom/projects/food/clean/foodsoft/app/controllers/application_controller.rb:81:in `set_time_zone'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:432:in `block in make_lambda'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:312:in `block in halting'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:497:in `block in around'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:505:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/callbacks.rb:19:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal/rescue.rb:29:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/notifications.rb:164:in `block in instrument'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/notifications.rb:164:in `instrument'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activerecord-4.2.11/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/abstract_controller/base.rb:137:in `process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionview-4.2.11/lib/action_view/rendering.rb:30:in `process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal.rb:196:in `dispatch'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_controller/metal.rb:237:in `block in action'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:43:in `serve'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/journey/router.rb:43:in `block in serve'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/journey/router.rb:30:in `each'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/journey/router.rb:30:in `serve'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/routing/route_set.rb:817:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/recurring_select-2.1.0/app/middleware/recurring_select_middleware.rb:24:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/exception_notification-4.2.2/lib/exception_notification/rack.rb:41:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/bullet-5.7.6/lib/bullet/rack.rb:14:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/meta_request-0.6.0/lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/meta_request-0.6.0/lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/etag.rb:24:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/conditionalget.rb:38:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/head.rb:13:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/flash.rb:260:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/session/abstract/id.rb:225:in `context'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/session/abstract/id.rb:220:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/cookies.rb:560:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activerecord-4.2.11/lib/active_record/query_cache.rb:36:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activerecord-4.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/reloader.rb:73:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-contrib-1.8.0/lib/rack/contrib/response_headers.rb:17:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/meta_request-0.6.0/lib/meta_request/middlewares/headers.rb:16:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/web-console-2.3.0/lib/web_console/middleware.rb:28:in `block in call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/rack/logger.rb:38:in `call_app'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/rack/logger.rb:20:in `block in call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/tagged_logging.rb:68:in `block in tagged'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/tagged_logging.rb:26:in `tagged'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/tagged_logging.rb:68:in `tagged'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/rack/logger.rb:20:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/quiet_assets-1.1.0/lib/quiet_assets.rb:27:in `call_with_quiet_assets'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/request_id.rb:21:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/methodoverride.rb:22:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/runtime.rb:18:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/activesupport-4.2.11/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/lock.rb:17:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/actionpack-4.2.11/lib/action_dispatch/middleware/static.rb:120:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/sendfile.rb:113:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/engine.rb:518:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/application.rb:165:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/content_length.rb:15:in `call'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/thin-1.7.2/lib/thin/connection.rb:86:in `block in pre_process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/thin-1.7.2/lib/thin/connection.rb:84:in `catch'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/thin-1.7.2/lib/thin/connection.rb:84:in `pre_process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/thin-1.7.2/lib/thin/connection.rb:53:in `process'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/thin-1.7.2/lib/thin/connection.rb:39:in `receive_data'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run_machine'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/thin-1.7.2/lib/thin/backends/base.rb:73:in `start'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/thin-1.7.2/lib/thin/server.rb:162:in `start'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/handler/thin.rb:19:in `run'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/rack-1.6.11/lib/rack/server.rb:287:in `start'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/commands/server.rb:80:in `start'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:80:in `block in server'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:75:in `tap'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:75:in `server'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
	from /home/tom/.rvm/gems/ruby-2.3.7/gems/railties-4.2.11/lib/rails/commands.rb:17:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'

carchrae avatar Mar 24 '19 16:03 carchrae

tom@saturn:~/projects/food/clean/foodsoft$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

carchrae avatar Mar 24 '19 16:03 carchrae

hmm. i think it was this commit. https://github.com/foodcoops/foodsoft/commit/43c1833cd71fbe90b2e6281fedb1e847b7baee04

the fix looks easy though. just need to ensure setup_mailing is called at least once when not running on multi coop mode

carchrae avatar Mar 24 '19 17:03 carchrae

i think probably it would be safer to always call FoodsoftConfig.select_foodcoop - and have the check about multi coops in there.

edit: i didn't end up doing this

carchrae avatar Mar 24 '19 17:03 carchrae

i still have some concerns about the logic for multi coop installs being littered around the code. IMHO, since multi-installs are a generalisation of a single coop, it would be nicer to always use the same code path - eg, and avoid checks like this one:

https://github.com/foodcoops/foodsoft/blob/9283ed4f5e9ad77cb9c0e86bdeb472324907f5e9/app/controllers/concerns/foodcoop_scope.rb#L18

carchrae avatar Mar 24 '19 18:03 carchrae

Thanks for taking the time to analyse this! I agree that we'd better always select a foodcoop, and have the logic there to handle single and multicoop functionality.

wvengen avatar Mar 26 '19 18:03 wvengen

the PR i submitted fixes the immediate issue of the mailer being broken. i would suggest going ahead with that PR, then refactoring all the if FoodsoftConfig[:multi_coop_install] code into config as a separate issue

carchrae avatar Mar 26 '19 19:03 carchrae

Just to note, I ran into this myself and appreciate the work done to debug this :rocket: I think https://github.com/foodcoops/foodsoft/issues/788 is a duplicate? For my work-aroud, I just used multi_coop = true but I think https://github.com/foodcoops/foodsoft/pull/841 has fixed this now, so probably this won't be necessary in a following release?

decentral1se avatar May 23 '21 13:05 decentral1se