I can not get current_user method in controllers inherited from WebsocketRails :: BaseController (in production environment). There is no error in the log, the controller simply stops execution. I am logging current_user and in the development environment I see the value, and in the production environment the variable is empty. What is the significant difference between running rails s -e development and rails s -e production ?

I even tried to copy configs from deva to production (config / environments / production.rb). But still.

I use the following gems for Ruby 2.2.0 and rails 4.2.0 rails:

 websocket-rails (0.7.0) faye-websocket (0.9.2) websocket-driver (>= 0.5.1) devise (3.4.1) 

Respectively, Thin server, for web-ketoa, I launch rake websocket_rails websocket_rails:start_server on port 3001 and connect to it correctly.

If you do not access current_user , but simply pull out any user from the database, the method works without problems, that is, the sockets are in order, the connection is there, the controller does not see the only Devise current_user, and this is only in the production environment.

After successful authorization in development in the log:

 current_user:#<User:0x00000005bfe988> 

In production in the log:

 current_user: 

Empty, although only Wednesday has changed.

PS everything is fine with the base, not websockets methods work correctly.

  • one
    You start the Websocket-rails server in Standalone mode. Do I understand correctly? - MAXOPKA 1:24 pm
  • Yes, I understood correctly. - Sergey Vlasov pm

1 answer 1

Try adding a method to a controller that inherits from WebsocketRails :: BaseController

 def cookies request.cookies end 

And another rake websocket_rails:start_server : by default, when you write the rake websocket_rails:start_server , then Rails starts in development mode, and therefore uses the configuration for the database from development mode, then, when connecting, a connection error occurs that is written to log/development (where and do not guess look).

To run Standalone Websocket server in production mode use the command

 rake websocket_rails:start_server RAILS_ENV=production 
  • Thank you rake websocket_rails:start_server RAILS_ENV=production - helped. - Sergey Vlasov 2:19 pm