1

I want to run some code around a rails console session (e.g. add log tagging, set database connection). For the rails server I can do this using middle ware, but can this also be done for the console?

see also: Rails7 MultiDB switch shard for console

Notalifeform
  • 194
  • 1
  • 8
  • It's possible but still belongs in the bad ideas column. The whole idea of middleware is that its used in a Rack application when processing HTTP requests. The Rails console is not responding to a request so the entire concept of middleware is not relevant. While you can instanciate your middleware with a faked request it really just begs the question why you're using the console for the task at hand and why you think middleware is the answer and not something like a separate environoment. You can beat a screw in with a hammer - but why? – max Feb 10 '22 at 17:16
  • Sometimes we need to do some things on the console (fixing data, checking out issues) on our production machines (or acceptance). Since we're using a sharded db it would be nice if we could set de default shard from the command line and and add tagged logging (so logs from a console session are the same as the ones origination from Rails/Sidekiq. So, I'm not looking for middle ware to fix this, but for a similar mechanism... – Notalifeform Feb 11 '22 at 18:28

0 Answers0