小编Jin*_*Lim的帖子

Rails 7 和导入映射以及加载自定义 JS 文件

我正在尝试加载我的自定义 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)\n

notification_controller.js

\n
import { 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

配置/导入映射.rb

\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-on-rails import-maps ruby-on-rails-7

9
推荐指数
1
解决办法
9697
查看次数

Ruby - 块何时执行?

我了解 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)

ruby closures block

5
推荐指数
1
解决办法
112
查看次数

红宝石线程。为什么“#加入”?

这听起来可能很愚蠢。但请指导我。

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 对象。这已经死了。

ruby multithreading

1
推荐指数
1
解决办法
373
查看次数

Rails 7,ActiveMailer smtp 未设置

我在 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

谁能帮我?

smtp ruby-on-rails actionmailer

0
推荐指数
1
解决办法
1080
查看次数