在控制器方法中,我将用户的变量设置为activation_sent_at等于Time.zone.now向该用户发送激活电子邮件的时间.在开发服务器上,这似乎有效(尽管我的应用程序中的时间表达式在我的计算机的本地时间落后2小时).
我想要包含一个集成测试,测试是否activation_sent_at确实设置得当.所以我加入了这条线:
assert_equal @user.activation_sent_at, Time.zone.now
Run Code Online (Sandbox Code Playgroud)
但是,这会产生错误:
No visible difference in the ActiveSupport::TimeWithZone#inspect output.
You should look at the implementation of #== on ActiveSupport::TimeWithZone or its members.
Run Code Online (Sandbox Code Playgroud)
我认为它建议Time.zone.now在我的测试中使用另一个表达式.我查看了不同的来源,包括http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html,但我不知道该怎么做.什么可能导致此错误的任何建议?
附加信息:添加puts Time.zone.now并puts @stakeholder.activation_sent_at确认两者相等.不确定是什么导致失败/错误.
我的 React 应用程序中有脚本,稍后会动态插入。脚本不加载。
\n在我的数据库中有一个名为 的字段content,其中包含包含 html 和 javascript 的数据。有很多记录,每个记录可以包含该content字段中的多个脚本。因此,在我的 React 应用程序中静态指定每个脚本 URL 并不是真正的选项。例如,记录的字段可能如下所示:
<p>Some text and html</p>\n<div id="xxx_hype_container">\n <script type="text/javascript" charset="utf-8" src="https://example.com/uploads/hype_generated_script.js?499892"></script>\n</div>\n<div style="display: none;" aria-hidden="true"> \n<div>Some text.</div> \nEtc\xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n我使用以下命令在我的 React 应用程序中调用此字段dangerouslySetInnerHTML:
render() {\n return (\n <div data-page="clarifies">\n <div className="container">\n <div dangerouslySetInnerHTML={{ __html: post.content }} />\n ... some other data\n </div>\n </div>\n );\n}\nRun Code Online (Sandbox Code Playgroud)\n它正确地从数据库加载数据并显示该数据的 html。但是,Javascript 不会被执行。我认为该脚本不起作用,因为它是稍后动态插入的。我怎样才能让这些脚本工作/运行?
\n这篇文章提出了动态插入脚本的解决方案,但我不认为我可以应用此解决方案,因为在我的情况下,脚本/代码是从数据库插入的(那么如何在nodeScriptReplace代码上使用...?)。有什么建议可以让我的脚本发挥作用吗?
更新回应 @lissettdm 他们的答案:
\nconstructor(props) …Run Code Online (Sandbox Code Playgroud) 我无法去Element.scrollIntoView()上班。我有下面的代码。根据某些变量,它应该滚动到两个位置。但是,它不会滚动到其中任何一个。我究竟做错了什么?
class Page extends Component {
scrollToMyRef = (id) => {
var ref = document.getElementById(id);
console.log("Ref1: " + ref); // returns [object HTMLElement]
console.log("Ref2: " + document.ref); // returns undefined
console.log("Id: " + id); // returns myRef
ref.scrollIntoView({
behavior: "smooth",
block: "start",
});
};
componentDidMount() {
if (this.props.location.state) {
if (this.props.location.state.origine) {
this.scrollToMyRef("myRef");
} else {
this.scrollToMyRef("myTopRef");
});
}
}
}
render() {
return (
<div
id="myTopRef"
key="pricing"
className="pricing"
>
...
</div>
<section id=myRef className="section">
...
</section>
... …Run Code Online (Sandbox Code Playgroud) 我发送一个电子邮件地址作为签名 cookie:
cookies.signed[:user_email] = { value: user.email, expires: 24.hours.from_now }
Run Code Online (Sandbox Code Playgroud)
之后,前端将其作为HTTP标头发送给我:
request.headers["HTTP_USER_EMAIL"]
Run Code Online (Sandbox Code Playgroud)
如何从收到的标题解密到原始电子邮件地址?我尝试了下面这一行,但它产生了错误:
NoMethodError异常:#String的未定义方法`signed':0x00000008a57a78
email = request.headers["HTTP_USER_EMAIL"].signed unless (request.headers["HTTP_USER_EMAIL"] == nil)
Run Code Online (Sandbox Code Playgroud)
随着debugger我得到一个值request.headers["HTTP_USER_EMAIL"]的"Im9yZ29utcGxlLmNvbSI=--37ddc725d139f86095ae839012c31a14e".所以加密值就在那里.
Cookie与标头的差异值:如果在cookie中找到加密值,则可以使用以下方法对其进行解密cookies.signed[:http_user_email].我尝试request.headers["HTTP_USER_EMAIL"].signed和request.headers.signed["HTTP_USER_EMAIL"]基本上与使用cookie的时候一样,你将获取cookie的加密值并在最后添加.signed : "Im9yZ29utcGxlL".signed. 这也行不通.但是,如果在字符串中找到加密值,那怎么办呢?
或者您是否认为不需要使用用户电子邮件地址的加密版本进行API身份验证?基于电子邮件地址和令牌的组合来完成认证(令牌需要匹配作为令牌的加密版本的摘要).
在迁移时,我收到以下错误消息:
PG::UndefinedTable: ERROR: relation "actioncodes" does not exist
: ALTER TABLE "organizations" ADD CONSTRAINT "fk_rails_4ecaa2493e"
FOREIGN KEY ("actioncode_id")
REFERENCES "actioncodes" ("id")
Run Code Online (Sandbox Code Playgroud)
我有以下组织的迁移文件:
class CreateOrganizations < ActiveRecord::Migration
def change
create_table :organizations do |t|
t.string :name, null: false, limit: 40
t.references :actioncode, index: true, foreign_key: true
t.boolean :activated
t.datetime :activated_at
t.timestamps null: false
end
end
end
Run Code Online (Sandbox Code Playgroud)
对于Actioncodes,我有迁移文件:
class CreateActioncodes < ActiveRecord::Migration
def change
create_table :actioncodes do |t|
t.string :code, null: false, limit: 20
t.string :description, limit: 255
t.timestamps null: false
end
end …Run Code Online (Sandbox Code Playgroud) 我正在使用Cloud9(railstutorial.org)并注意到我的工作区使用的磁盘空间正朝着磁盘配额快速增长.
有没有办法清理工作区,从而减少使用的磁盘空间?
工作区目前为817MB(见下文使用quota -s).我下载它来查看目录的大小,我不明白.包含我的项目的目录只有170 MB大小,.9文件夹只有3 MB.所以这并没有接近817 MB ...而且使用的磁盘空间不断增长,即使我没有对我的项目内容进行任何重大更改.
Size Used Avail Use%
1.1G 817M 222M 79%
Run Code Online (Sandbox Code Playgroud)
它可能与.9文件夹有关吗?例如,我手动删除了几个子项目,但在.9文件夹中这些项目仍然存在,包括他们的文件.我也想知道是否可能在.9文件夹中安装了不同版本的宝石......所以如果你更新一个宝石,它会包含两个版本的宝石.
我不确定这个文件夹或Cloud9存储一般如何工作,但我的问题是如何清理磁盘空间(不必删除我项目中的任何内容)?是否有一些清理功能?我当然可以创建一个新工作区并在那里上传我的项目,但也许在保持当前工作空间的同时还有另一种选择.
我尝试将我的应用程序推送到heroku但是出现以下错误:
remote: -----> Using Ruby version: ruby-2.2.2
remote: -----> Installing dependencies using 1.9.7
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote: Fetching gem metadata from https://rubygems.org/...........
remote: Fetching version metadata from https://rubygems.org/...
remote: Fetching dependency metadata from https://rubygems.org/..
remote: Could not find net-ssh-2.10.0 in any of the sources
remote: Bundler Output: Fetching gem metadata from https://rubygems.org/...........
remote: Fetching version metadata from https://rubygems.org/...
remote: Fetching dependency metadata from https://rubygems.org/..
remote: Could not find net-ssh-2.10.0 in any …Run Code Online (Sandbox Code Playgroud) 对于用户配置文件,我正在尝试创建一个圆形图像以及一个与图像高度相同的水平条.此外,它应该是响应.它应该如下图所示.在黑色栏中会有文字.

有人可以用正确的CSS帮助我吗?
到目前为止,我有下面的代码,但这已经出错,因为黑条位于圆圈下方而不是旁边.但我也不知道如何让黑条准确地从图像中间开始,将图像放在顶部,并使黑条中的文字充分向右开始(同时响应屏幕尺寸) .
<div class="col-md-12 profile-topbar">
<div class="round">
<img src=<%= image_path('profile.gif') %>>
</div>
<div class="text-bar">
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在我的CSS文件中:
.round {
margin: 2em;
border-radius: 50%;
overflow: hidden;
width: 150px;
height: 150px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
box-shadow: 0 0 8px rgba(0, 0, 0, .8);
-webkit-box-shadow: 0 0 8px rgba(0, 0, 0, .8);
-moz-box-shadow: 0 0 8px rgba(0, 0, 0, .8);
}
.round img {
display: block;
width: 100%;
height: 100%;
}
.text-bar {
display: inline-block;
background: #FFF;
left: 222px; //Problem: …Run Code Online (Sandbox Code Playgroud) A link有两个components:componenta_id和componentb_id.为此,Link我在模型文件中有:
belongs_to :componenta, class_name: "Component"
belongs_to :componentb, class_name: "Component"
validates :componenta_id, presence: true
validates :componentb_id, presence: true
validates :componenta_id, uniqueness: { scope: :componentb_id }
validates :componentb_id, uniqueness: { scope: :componenta_id }
Run Code Online (Sandbox Code Playgroud)
并在迁移文件中:
create_table :links do |t|
t.integer :componenta_id, null: false
t.integer :componentb_id, null: false
...
end
add_index :links, :componenta_id
add_index :links, :componentb_id
add_index :links, [:componenta_id, :componentb_id], unique: true
Run Code Online (Sandbox Code Playgroud)
问题:这一切都有效.现在,无论他们的顺序如何,我都想要它们的组合componanta和componentb独特性.因此无论哪个组件是哪个组件(componenta哪个是componentb相同的链接;两个相同组件之间的链接).因此,不应允许下面的两个记录,因为它们代表相同的链接,因此不是唯一的:
我有一个邮戳电子邮件模板,其中动态变量包含 html。但是,它将该 html 处理为纯文本。
更具体地说,我有下面的代码。该变量body被发送到电子邮件模板,但是<br><br>显示为文本,而不是转到下一行。
在控制器中:
const body = "Hi...<br><br> Welcome to our a new episode.";
client.sendEmailWithTemplate(
{
TemplateAlias: process.env.POSTMARK_TEMPLATE,
TemplateModel: {
body: body
},
From: from,
To: email,
});
Run Code Online (Sandbox Code Playgroud)
在邮戳模板中:
<tr>
<td>
1. The following includes text with a br break: {{body}}
</td>
</tr>
<tr>
<td>
2. This line includes a br break directly in the template: How are you? <br> Anything new?
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
这会生成一封电子邮件,其中 br 中断在位置 2 上起作用,但在位置 1 上不起作用。在位置 1 上<br> …
javascript ×2
ruby ×2
bundler ×1
cloud9-ide ×1
cookies ×1
css ×1
css-shapes ×1
css3 ×1
deployment ×1
email ×1
encryption ×1
heroku ×1
html ×1
migration ×1
model ×1
node.js ×1
postgresql ×1
postmark ×1
reactjs ×1
security ×1
templates ×1
validation ×1