Rails 新手采坑记录

不带括号的方法调用之殇

在Rails integration test里面执行post请求:

post room_messages_path target_room, message: {body: 'hello'}, token: 'user_token', format: :turbo_stream

你以为后面的message: {body: 'hello'}, token: 'user_token', format: :turbo_stream都是post的参数?room_messages_path的参数只是target_room

其实错了!target_room, message: {body: 'hello'}, token: 'user_token', format: :turbo_stream都是room_messages_path的参数,post的参数只有一个,就是那个path:room_messages_path(target_room, message: {body: 'hello'}, token: 'user_token', format: :turbo_stream)

不得不说,这种不带括号的写法,很多时候确实很迷惑🤣

Production环境下ActionCable无法建立连接

Chrome Console 提示 WebSocket connection to 'wss://rails.weallwitness.com/cable' failed: ,server log提示 [some_port:puma srv tp 001 tagged_logger_proxy.rb:38] [some request id] ActionCable -- Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: close, HTTP_UPGRADE: ) 然后就没有其他错误日志了。
解决办法:在nginx里面加上一下两行

  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";

Leave a Reply