我有这个柜台,但是我希望它能永远运行,这很简单,我在这里做错了什么?
function timer() {
console.log("timer!")
}
window.setInterval(timer(), 1000)
Run Code Online (Sandbox Code Playgroud) 我正在使用 rails 5.2.1 内容安全策略 DSL 实现 CSP。我的政策设置为:
Rails.application.config.content_security_policy do |policy|
policy.default_src :self, :https
policy.connect_src :self
#...
policy.script_src :self
end
# If you are using UJS then enable automatic nonce generation
Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
Run Code Online (Sandbox Code Playgroud)
我也有<%= csp_meta_tag %>
我的application.html.erb
在这一点上,我需要向nonce: true
任何内联脚本添加一个标志以满足策略。我已经这样做了,它按预期工作。但是,我无法维护现有的 AJAX 样式功能。例如,我有类似的东西(注意remote: true
):
# index.html.erb
<%= link_to create_object_path, id: "#{object.code}",method: :post, remote: true do %>
<button type="button">Create object</button>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在我的控制器中
def create
@object = current_user.object.create
respond_to do |format|
if …
Run Code Online (Sandbox Code Playgroud) 我正在尝试允许用户在我的主页/目标网页上注册该网站.我已将设计注册表复制到我的目标网页视图中 -
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :first_name %><br />
<%= f.text_field :first_name %></div>
<div><%= f.label :last_name %><br />
<%= f.text_field :last_name %></div>
<div><%= f.label :profile_name %><br />
<%= f.text_field :profile_name %></div>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render …
Run Code Online (Sandbox Code Playgroud) 我希望能够在发送设计邀请时显示发出邀请的用户而不仅仅是我的域名,但无法找到任何相关文档.
我需要显示此名称的两个地方在邀请电子邮件中 -
(代替'某人')
<p>Hello <%= @resource.email %>!</p>
<p>Someone has invited you to <%= root_url %>, you can accept it through the link below.</p>
<p><%= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %></p>
<p>If you don't want to accept the invitation, please ignore this email.<br />
Your account won't be created until you access the link above and set your password.</p>
Run Code Online (Sandbox Code Playgroud)
和设置密码页面.
<h4>You're seeing this page because someone has invited you to the site</h4>
<%= simple_form_for resource, :as => resource_name, …
Run Code Online (Sandbox Code Playgroud) 运行rails控制台时,我Rails.configuration.secret_key_base
在开发环境中的调用会保持返回nil.
#secrets.yml
development:
secret_key_base: the-long-secret-generated-by-rake-secret
#...other configs, a call while running heroku rails c in production also returns nil
Run Code Online (Sandbox Code Playgroud)
怎么会这样?运行导轨4.1.0
我需要制作一个重复给定单词的方法,但我认为我的设计错了.我需要在单词之间留出空格,我在这里缺少什么?
def repeat(word, repeats=2)
sentence = word.to_s * repeats
return sentence
end
Run Code Online (Sandbox Code Playgroud) 我不明白为什么我的rake任务不是从resque工作者中运行的.运行
rake :send_this_email
Run Code Online (Sandbox Code Playgroud)
从控制台工作正常,我只想将它作为一个cron作业运行(如下所示)但是在从工作者中调用rake任务时,某些东西不能正常工作.
我的 rescue_schedule.yml
send_this_email:
cron: "*/2 * * * *"
class: SendThisEmailWorker
args:
description: "Send email when condition defined in rake task is met"
Run Code Online (Sandbox Code Playgroud)
我send_this_email_worker.rb
的workers
目录,如果我可以从控制台手动调用rake任务,问题必须在哪里?
require 'rake'
module SendThisEmailWorker
@queue = :send_this_email
def self.perform
Rake::Task["send_this_email"].invoke
end
end
Run Code Online (Sandbox Code Playgroud)
当我启动我的开发服务器时,这个send_this_email
rake任务应该每2分钟运行一次吗?它不是,resque管理面板将其显示为队列中的作业.我在这里错过了什么?
感谢您的关注.
从gerep评论更新
require 'rake'
module SendThisEmailWorker
@queue = :send_this_email
def self.perform
puts "Hi from the console, I'm started"
Rake::Task["send_this_email"].invoke
end
end
Run Code Online (Sandbox Code Playgroud) 我想在启动开发服务器时启动我的工作人员来测试 resque 调度程序中的新 cron 作业,因此我在启动开发服务器时运行此命令 -
QUEUE=* rake environment resque:work rails s
Run Code Online (Sandbox Code Playgroud)
它以前对我有用,如果我正确阅读他们的文档,它应该仍然有效。
但在挂断后中断它后,我收到以下错误 -
^Crake aborted!
Don't know how to build task 'rails'
Run Code Online (Sandbox Code Playgroud)
这是键盘中断并运行后得到的结果--trace
** Invoke environment (first_time)
** Execute environment
** Invoke resque:work (first_time)
** Invoke resque:preload (first_time)
** Invoke resque:setup (first_time)
** Invoke environment
** Execute resque:setup
** Execute resque:preload
** Invoke resque:setup
** Execute resque:work
^Crake aborted!
Don't know how to build task 'rails'
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我会收到错误,另外为什么它以前加载并工作但现在不再加载了。我在这里缺少什么?
我不知道为什么无法在heroku服务器上设置gmail env变量。我跑,并设置用户名轻松地根据自己的文档,通过运行
heroku config:add GMAIL_USERNAME=usersname@gmail.com
Run Code Online (Sandbox Code Playgroud)
但是,现在当我尝试设置密码以与之配合使用时,可以在邮件中使用
heroku config:add GMAIL_PASSWORD=mypassword
Run Code Online (Sandbox Code Playgroud)
我遇到了错误
zsh: no matches found: GMAIL_PASSWORD=mypassword
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我不能以这种方式设置此变量,更不用说为什么要从我的shell中获得此输出了。
关于我这部分设置的几件事。
- loca_env.yml
用于签入的邮件用户名和密码.gitignore
(因此在heroku服务器上进行设置)。
邮件初始化程序-
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:authentication => :plain,
:user_name => ENV["GMAIL_USERNAME"],
:password => ENV["GMAIL_PASSWORD"]
}
ActionMailer::Base.default_url_options[:host] = "myapp.herokuapp.com"
Run Code Online (Sandbox Code Playgroud)
它可以在本地正常发送邮件,现在我正尝试在生产环境中进行测试,而无需检local_env.yml
入版本控制。我不明白的简单东西?
我试图在Gemfile.lock
没有明确这样做的情况下追踪几个平台是如何添加到我的。在添加新 gem 时,我一定忽略了这些更改,但是Gemfile.lock
在添加相同的Gemfile
更改时,我无法重现相同的平台添加内容。
这是添加新平台的提交。
#....
+gem 'sqreen'
+gem 'sanitize'
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
@@ -55,6 +57,8 @@ gem 'postmark-rails'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
+ gem 'capybara'
+ gem 'selenium-webdriver'
end
Run Code Online (Sandbox Code Playgroud)
以及Gemfile.lock
在同一次提交中的更改:
PLATFORMS
+ java
ruby
+ x64-mingw32
+ x86-mingw32
+ x86-mswin32
Run Code Online (Sandbox Code Playgroud)
我尝试在测试应用程序中重现相同的修改,但这些平台未添加到 Gemfile.lock …
devise ×2
heroku ×2
javascript ×2
redis ×2
resque ×2
ruby ×2
ajax ×1
callback ×1
controller ×1
email ×1
gemfile.lock ×1
invitation ×1
mailer ×1
methods ×1
rake ×1
rubygems ×1
setinterval ×1
view ×1