我正在尝试在端口 5000 上运行 Node JS 项目,但我不能:
错误:监听 EADDRINUSE:地址已在使用中 :::5000
看起来一切都很简单,但是:
lsof -i tcp:5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 395 colibri 22u IPv4 0x361e8dfd90bd1ee9 0t0 TCP *:commplex-main (LISTEN)
ControlCe 395 colibri 23u IPv6 0x361e8dfd8b640a61 0t0 TCP *:commplex-main (LISTEN)
Run Code Online (Sandbox Code Playgroud)
“ControlCe”是 macOS 12.0.1 中的“ControlCenter”。
您能否告诉我是否有办法在端口 5000 上运行应用程序,或者现在我需要使用端口 5010?
有很多对很多:
class Employee < ActiveRecord::Base
has_many :employees_and_positions
has_many :employees_positions, through: :employees_and_positions
end
class EmployeesAndPosition < ActiveRecord::Base
belongs_to :employee
belongs_to :employees_position
end
class EmployeesPosition < ActiveRecord::Base
has_many :employees_and_positions
has_many :employees, through: :employees_and_positions
end
Run Code Online (Sandbox Code Playgroud)
添加员工时如何在表单中实现选择(check_boxes)职位?我写了这个变体:
f.inputs 'Communications' do
f.input :employees_positions, as: :check_boxes
end
Run Code Online (Sandbox Code Playgroud)
它在表单中显示职位列表,但不将任何内容保存到表中(employees_and_positions)。怎么修?
我在 Rails 5.0.0 上创建了一个项目。
此外,我做了与此视频完全相同的操作:https : //www.youtube.com/watch?v=n0WUjGkDFS0
除了生成的频道。我生成了两个频道:聊天和评论。
我也并行阅读:https : //github.com/rails/rails/tree/master/actioncable
在 routes.rb 我添加了这一行:
mount ActionCable.server => '/cable'
在 application.rb 我添加了这一行:
config.action_cable.mount_path = '/cable'
结果,我运行了这个命令的项目:
rails server -b SERVER_IP -p 3020
此错误显示在控制台浏览器中:
与“ws://site.com/cable”的 WebSocket 连接失败:意外响应代码:404
运行项目的一段日志:
Started GET "/cable" for SERVER_IP at 2016-07-12 16:20:14 +0300
Cannot render console from SERVER_IP! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started GET "/cable/" [WebSocket] for SERVER_IP at 2016-07-12 16:20:14 +0300
Request origin not allowed: example.com
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: …Run Code Online (Sandbox Code Playgroud) 我做了这个样本:https://github.com/Akryum/vueconf-2017-demo
因此,我的项目中有相同的文件:https://github.com/Akryum/vueconf-2017-demo/blob/master/src/apollo-client.js
这是我的应用程序中使用的代码:
import { ApolloClient, createNetworkInterface } from 'apollo-client'
const apolloClient = new ApolloClient({
networkInterface: createNetworkInterface({
uri: 'http://localhost:3000/graphql',
transportBatching: true,
}),
connectToDevTools: true,
})
export default apolloClient
Run Code Online (Sandbox Code Playgroud)
结果,我得到控制台的错误(警告):
warning in ./src/apollo/client.js
15:23-45 "export 'createNetworkInterface' was not found in 'apollo-client'
Run Code Online (Sandbox Code Playgroud)
这是来自浏览器控制台:
TypeError: Object(__WEBPACK_IMPORTED_MODULE_0_apollo_client__["createNetworkInterface"]) is not a function. (In 'Object(__WEBPACK_IMPORTED_MODULE_0_apollo_client__["createNetworkInterface"])({
uri: 'http://localhost:3000/graphql',
transportBatching: true
})', 'Object(__WEBPACK_IMPORTED_MODULE_0_apollo_client__["createNetworkInterface"])' is an instance of Object)
Run Code Online (Sandbox Code Playgroud)
问题是什么?
文档:https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-dig
我运行rails c并写下这个:
params = ActionController::Parameters.new(foo: { bar: { baz: 1 } })
Run Code Online (Sandbox Code Playgroud)
并进一步:
params.dig(:foo, :bar, :baz)
Run Code Online (Sandbox Code Playgroud)
这两行是我从页面上截取的,上面给出了链接。
结果,我得到了nil。
工作时Hash一切都很好。使用时出现问题ActionController::Parameters。我在 Rails 应用程序中遇到了这个问题。
需要您对此的意见。
最近在 DigitalOcean 有机会创建数据库。这有点像基于通常的 Droplet 的交钥匙解决方案,带有一堆附加的数据库功能。
这些附加功能之一 - 连接池。据我了解,这是一个 PgBouncer。
如果我以通常的方式(直接)将数据库连接到 Rails 5.2 应用程序,那么一切都很好。
但是如果我通过“连接池”使用连接,我会得到一个错误:
ActiveRecord::StatementInvalid: PG::DuplicatePstatement: 错误: 准备好的语句“a1”已经存在
当从数据库接收到任何数据时,就会发生这种情况。
请告诉我,如何使它全部工作?
有一个information具有此结构的 JSONB字段:
{
"ignore"=>false
}
Run Code Online (Sandbox Code Playgroud)
我想获取其ignore字段为的所有记录true:
{
"ignore"=>false
}
Run Code Online (Sandbox Code Playgroud)
此行引发错误:
PG::UndefinedFunction: ERROR: operator does not exist: text = boolean
Run Code Online (Sandbox Code Playgroud)
我在谷歌找不到任何东西。我们到处都在谈论文本含义。但是没有关于布尔值的内容。
我有一个来自 GraphQL 的对象。我需要处理一个字段,然后返回一个哈希值。
为此,我最初尝试使用该to_h方法。但是当我尝试更改该字段中的值时,出现此错误:
FrozenError - 无法修改冻结的哈希值
然后我就产生了使用该方法的想法dup。这个方法似乎“解冻”了原始对象:
object.to_h.dup
Run Code Online (Sandbox Code Playgroud)
但这对于“深”领域没有帮助。对于“深层”字段,我必须使用本地dup方法。
请告诉我是否有更正确的解决方案?
代码示例:
create_data_with(
first: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
second: <<~TEXT
Aenean vel ex bibendum, egestas tortor sit amet, tempus lorem. Ut sit
amet rhoncus eros. Vestibulum ante ipsum primis in faucibus orci
luctus et ultrices posuere cubilia curae; Quisque non risus vel lacus
tristique laoreet. Curabitur quis auctor mauris, nec tempus mauris.
TEXT,
third: "Nunc aliquet ipsum at semper sodales."
)
Run Code Online (Sandbox Code Playgroud)
错误出现在这一行:
second: <<~TEXT
Run Code Online (Sandbox Code Playgroud)
RuboCop 是这样描述的:
Lint/Syntax: unterminated string meets end of file
(Using Ruby 3.1 parser; …Run Code Online (Sandbox Code Playgroud) 有一个哈希的例子:
h1 = {
a1: :a2,
b1: :b2,
c1: :c2,
d1: :d2,
e1: :e2,
f1: :f2
}
Run Code Online (Sandbox Code Playgroud)
并且有这样一个键数组:
a1 = [:b1, :d1, :f1]
Run Code Online (Sandbox Code Playgroud)
如何根据数组对这个哈希的键进行排序?不在数组中的哈希键必须按其原来的顺序位于已排序的哈希键之后。
结果:
{
b1: :b2,
d1: :d2,
f1: :f2,
a1: :a2,
c1: :c2,
e1: :e2
}
Run Code Online (Sandbox Code Playgroud) ruby ×3
postgresql ×2
actioncable ×1
activeadmin ×1
activerecord ×1
apollo ×1
graphql ×1
graphql-js ×1
javascript ×1
macos ×1
nginx ×1
node.js ×1
pgbouncer ×1
ruby-3 ×1
ruby-3.1 ×1
vue-apollo ×1
websocket ×1