我正在尝试加载我的自定义 js。但出现错误。
\n错误如下。
\n无法注册控制器:通知(controllers/notification_controller)错误:无法解析从http://localhost:3000/assets/controllers/notification_contr导入的说明符“@noty”...
\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 javascript\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 application.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 controllers\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 application.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 notification_controller.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lib\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 noty.js\n
Run Code Online (Sandbox Code Playgroud)\nimport { Controller } from "@hotwired/stimulus"\nimport Noty from "@noty"\n\nexport default class extends Controller {\n static targets = [ 'type', 'message' ]\n\n ....// some codes.\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n# Pin npm packages by running ./bin/importmap\n\npin "application", preload: true\npin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true\npin "@hotwired/stimulus", …
Run Code Online (Sandbox Code Playgroud) 我了解 ruby 的block
工作原理。
block_test.rb
def foo
yield if block_given?
end
my_block = foo { puts "hello" }
Run Code Online (Sandbox Code Playgroud)
如果我跑,ruby block_test.rb
. 当然,它会按您的预期打印“你好”。
hello
Run Code Online (Sandbox Code Playgroud)
但我的问题是我什么时候执行了 ruby 块?我没有在任何地方调用 foo 方法。
我没有写——foo()
诸如此类。
# I defined `foo` method here as [If a block has been given, execute it.] but did not call.
def foo
yield if block_given?
end
# I also defined block of `foo` as [print 'hello'] and store into `my_block` variable.
# But I did not say execute …
Run Code Online (Sandbox Code Playgroud) 这听起来可能很愚蠢。但请指导我。
https://apidock.com/ruby/Thread/join
a = Thread.new { print "a"; }
a.join(5)
Run Code Online (Sandbox Code Playgroud)
正如我们在这里看到的,#join
方法基本上是“嘿操作系统,从现在起 5 秒后运行此代码块(线程)”。
但这个名字从何而来?join
。为什么不只是run
?
在Java中,它的含义似乎略有不同。
我发现这实际上#join
是阻塞呼叫。这意味着5秒后检查线程是否完成。如果finished
,则终止该线程。(X) 。join 将返回 Thread 对象。这已经死了。
我在 config/development.rb 中有这个
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey',
:password => '****',
:domain => 'yourdomain.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
如果在运行时运行它,
(byebug) Rails.configuration.action_mailer.smtp_settings
{:open_timeout=>5, :read_timeout=>5}
(byebug)
Run Code Online (Sandbox Code Playgroud)
似乎不需要完整设置。我怀疑这最终不会发送错误的电子邮件
*** Errno::ECONNREFUSED 异常:连接被拒绝 - connect(2) for 127.0.0.1:25
谁能帮我?