- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法使用 docker 在我的 ubuntu 服务器上正确运行 actioncable
这似乎是一种设备验证错误,这是我的终端日志
There was an exception - NoMethodError(undefined method `user' for nil:NilClass)
cable_1 | /var/www/acim/public/app/channels/application_cable/connection.rb:17:in `find_verified_user'
这是我的/app/chanels/application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.email
end
protected
def find_verified_user
if (current_user = env['warden'].user)
#if current_user = User.find_by(id: cookies.signed[:user_id])
current_user
else
reject_unauthorized_connection
end
end
end
end
* 这里是 config/environments/production.rb *
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
config.action_cable.url = 'ws://192.168.99.100/cable'
config.action_cable.allowed_request_origins = [ 'http://192.168.99.100', /http:\/\/192.168.99.100.*/, 'http://localhost' ]
#config.action_cable.url = [/ws:\/\/*/, /wss:\/\/*/]
#config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "ACIM_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# ne pas directement servir les fichiers public
# en utilisant ruby, mais passons par NGINX
config.public_file_server.enabled = false
config.assets.js_compressor = Uglifier.new(harmony: true)
end
Rails.application.config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb )
这是我的 docker-compose.yml 文件
version: '3'
services:
db:
image: postgres:9.6
environment:
- ACIM_DATABASE_PASSWORD=ACIM_2018
volumes:
- 'db:/var/lib/postgresql/data'
env_file:
- '.env'
expose:
- '5432'
ports:
- "7000:5432"
nginx:
image: nginx:latest
container_name: production_nginx
volumes:
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf
- public-content:/var/www/acim/public
ports:
- 80:80
- 443:443
links:
- web
redis:
image: redis
command: redis-server
volumes:
- 'redis:/data'
ports:
- "6379"
sidekiq:
build: .
#command: sidekiq -C config/sidekiq.yml
command: bundle exec sidekiq
volumes:
- .:/ACIM
links:
- db
- redis
depends_on:
- db
- redis
env_file:
- '.env'
web:
build: .
# command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- bundle_cache:/bundle
- public-content:/var/www/acim/public
- .:/ACIM
ports:
- "5000:3000"
depends_on:
- db
- redis
env_file:
- '.env'
cable:
depends_on:
- 'redis'
build: .
command: puma -p 28080 cable/config.ru
ports:
- '28080:28080'
volumes:
- '.:/ACIM'
env_file:
- '.env'
volumes:
bundle_cache:
redis:
db:
public-content:
请帮忙,
这两天以来我都快要死了!
提前致谢
最佳答案
我有一个工作设置,使用您评论过的 Warden Cookie 变体以及 Warden_hooks 初始化程序来管理 Cookie 的创建和失效
/app/chanels/application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
private
def find_verified_user
if current_user = User.find_by(id: cookies.signed['user_token'])
current_user.id
else
reject_unauthorized_connection
end
end
end
end
/app/config/initializers/warden_hooks.rb
# frozen_string_literal: true
# Set user_token cookie after sign in
Warden::Manager.after_set_user do |user, auth, opts|
scope = opts[:scope]
auth.cookies.signed["#{scope}_token"] = user.id
end
# Invalidate user.id cookie on sign out
Warden::Manager.before_logout do |user, auth, opts|
scope = opts[:scope]
auth.cookies.signed["#{scope}_token"] = nil
end
关于ruby-on-rails - actioncable 无法与生产设备配合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54137449/
我的应用程序中有两个设计身份验证模型,并且想要在它们之间创建聊天。有人可以帮我为用户编写连接吗?以下是我所拥有的。我想检查是否可以让两个连接根据不同用户的个人登录拒绝其连接。如有任何帮助,我们将不胜感
根据 Sitepoint's tutorial,我在我的 RoR 应用程序中使用 ActionCable,旨在用作 Angular 色扮演的聊天室。 .我已经设置好了,并且消息如预期的那样在创建消息时
我看过ActionCable.server.open_connections_statistics、ActionCable.server.connections.length、ActionCable.
我正在尝试使用我的 rails 5 应用程序设置 ActionCables,我已经运行了 rails g channel Posts,现在我的服务器每隔几秒就会重置一次,并出现此错误: Started
这在 Rails 中没有记录,但 ActionCable 有一个名为 PeriodicTimers 的模块 https://github.com/rails/rails/blob/master/act
我一直在尝试 ActionCable 并想知道它将尝试打开多少个数据库连接。是每个实例一个还是每个消费者连接一个?让 100k 消费者为每个消费者打开一个数据库连接会破坏数据库。 最佳答案 这取决于工
我无法手动关闭我的套接字。 只有当我关闭浏览器中的选项卡时它才会退出。 Finished "/cable/" [WebSocket] for 127.0.0.1 at 2016-10-29 16:55
我正在关注迈克尔·哈特尔 tutorial关于 Rails 5 ActionCable,建立一个简单的聊天,我的 create 内部出现问题行动在 MessageController : def
在我的项目中,我有一个模型categories,它具有一个详细 View (显示)。该 View 包含应使用actioncable进行实时更新的数据。 View 的内容/数据对于理解问题并不重要。 一
我使用 ActionCable 创建了以下内容,但无法接收任何正在广播的数据。 评论 channel : class CommentsChannel < ApplicationCable::Chann
我正在尝试让 ActionCable 在子域上工作。 问题是,一旦我更改以下行 config.action_cable.mount_path = '/' 该应用程序不再运行。但 ActionCable
我正在尝试使用Action Cable创建一个简单的类似于聊天的应用程序(计划扑克应用程序)。我对术语,文件层次结构以及回调如何工作感到有些困惑。 这是创建用户 session 的操作: class
我无法使用 docker 在我的 ubuntu 服务器上正确运行 actioncable 这似乎是一种设备验证错误,这是我的终端日志 There was an exception - NoMeth
我最近一直在尝试为 Squash 比赛创建一个实时计分系统。我已经设法将 ActionCable 与 Rails 5 一起使用来自动更新页面上的分数,但我想知道是否可以告诉 Rails 在满足特定条件
我正在使用 Ruby on Rails 5 作为后端框架,实际上是用于 websocket 连接的电缆和前端 Android。我按照 https://github.com/rails/actionca
有什么方法可以通过 ActionCable 传递文件吗?我正在尝试使用 Paperclip 进行上传。 我的 JavaScript 是 return $('#new_messag
我正在创建一个 ruby 应用程序,我正在尝试实现操作电缆,当用户发布帖子时,我希望为所有用户更新帖子索引。在我的 channels/posts.js 中我有: App.posts = App.c
我正在 rails 5 中实现 action cable,它在本地运行良好,但在暂存和生产中,在将消息发送到 action cable rails logger 之后。 [ActionCable] B
我有一个 Rails 5 应用程序,它使用 Action Cable 来实现 websocket 功能。 在我的开发环境中,一切都按预期进行,浏览器客户端成功连接到 Action Cable chan
在我的 Ruby on Rails 项目中,我有一个 Tickets MVC。用于编辑工单(例如 ID 为 5 的工单)的典型页面是 /tickets/5/edit。 在另一个页面上,我有一个简单的表
我是一名优秀的程序员,十分优秀!