小编eve*_*992的帖子

Rails资产管道不包括application.js清单中的必需文件

rails资产管道不包括application.js中所需的文件.

呈现给浏览器的唯一javascript文件是application.js,并且require行不会被编译为包含标记,因为它们应该是:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails asset-pipeline

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

Ember Data对删除记录的期望是什么?

我正在使用带有rails后端的RESTful适配器的Ember Data.

当我从灰烬中删除记录record.deleteRecord(); record.save()DELETE请求转到服务器和模型将被删除,但这个错误打印到JavaScript控制台:

Extract requested, but no data given for App.ThisModel. This may cause weird problems.
Run Code Online (Sandbox Code Playgroud)

来自服务器的响应是render json: true,所以我将其更改为render json: deleted_model渲染已删除记录的json.

这摆脱了以前的错误,但现在删除的记录在Ember中重新创建.

Ember在回复中期望什么?

ruby-on-rails ember.js ember-data

9
推荐指数
2
解决办法
3131
查看次数

为什么check_box表单助手会生成两个复选框,一个隐藏?

此代码:= form_fo:store_products do | f | = f.check_box:track_inventory

创建这个HTML:

<input name="product_group[products_attributes][0][store_products_attributes}[1342647745501][track_inventory]" type="hidden" value="0">

<input id="product_group_products_attributes_0_store_products_attributes_1342647745501_track_inventory" name="product_group[products_attributes][0][store_products_attributes][1342647745501][track_inventory]" type="checkbox" value="1">
Run Code Online (Sandbox Code Playgroud)

第一个隐藏元素的原因是什么?

ruby-on-rails form-helpers

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

构造函数中的析构参数属性

Typescript允许参数属性

class ParameterProperty {
  constructor(private member: number) {}
}
Run Code Online (Sandbox Code Playgroud)

上面创建了一个带私有成员的类member,构造函数设置this.member为构造函数的第一个参数.

但是,通过解构没有"命名参数"的等价物.

interface DestructedOptions {
  prefix: string;
  suffix: string;
}

class Destructed {
  constructor({private prefix, private suffix}: DestructedOptions) {}
}
Run Code Online (Sandbox Code Playgroud)

以上不起作用,你必须做这样的事情:

class Destructed {
  private prefix: string
  private suffix: string
  constructor({prefix, suffix}: DestructedOptions) {
    this.prefix = prefix;
    this.suffix = suffix;
  }
}
Run Code Online (Sandbox Code Playgroud)

这是非常详细的,并且在添加新属性时需要更新三个地方DestructuredOptions.我尝试了类似的东西,使用映射属性

class Destructed {
  private [P in keyof DestructedOptions]: T[DestructedOptions];
  constructor(opts: DestructedOptions) {
    Object.assign(this, opts)
  }
}
Run Code Online (Sandbox Code Playgroud)

只是发现映射的属性只能用于Types,而不能用于接口或类.我不喜欢这个选项,因为它复制了opts中的所有内容,我真的想要这样的东西:

class Destructed {
  constructor(opts: DestructedOptions) …
Run Code Online (Sandbox Code Playgroud)

typescript

8
推荐指数
2
解决办法
4405
查看次数

如何在 AWS 洞察中可视化由多个维度聚合的时间序列数据?

我想使用 cloudwatch 洞察来可视化主机随时间变化的平均延迟的多线图。每个主机一行。

此统计查询提取延迟并按主机将其聚合到 10 分钟的存储桶中,但它不会生成任何可视化效果。

stats avg(latencyMS) by bin(10m), host

bin(10m) | host | avg(latencyMS)
0m       |    1 |           120
0m       |    2 |           220
10m      |    1 |           130
10m      |    2 |           230
Run Code Online (Sandbox Code Playgroud)

文档称这是一个常见的错误,但没有提供任何替代方案。

以下查询不会生成可视化,因为它包含多个分组字段。

stats avg(myfield1) by bin(5m), myfield4
Run Code Online (Sandbox Code Playgroud)

aws 文档

实验上,如果每条记录有多个键,cloudwatch 会生成一个多线图。生成折线图的查询必须返回如下结果:

bin(10m) | host-1 avg(latencyMS) | host-2 avg(latencyMS)
0m       |    120                |                   220
10m      |    130                |                   230
Run Code Online (Sandbox Code Playgroud)

我不知道如何编写输出该查询的查询。

amazon-web-services amazon-cloudwatchlogs aws-cloudwatch-log-insights

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

用于改善单元测试的 elasticsearch 启动时间的设置?

我正在编写启动 elasticsearch 6.4 单节点集群的测试,以确保我的查询按预期运行。集群大约需要 10 秒才能启动我的测试 RestHighLevelClient 以 ping 它而没有连接错误

Process proc = new ProcessBuilder("elasticsearch").start();
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
  new HttpHost('localhost', 9200, 'http'),
  new HttpHost('localhost', 9201, 'http'),

));

// wait for cluster, takes about 10 seconds in practice.
do {
  try {
    client.ping(RequestOptions.DEFAULT);
    break;
  } catch (IOException ex) { }
} while (true);
Run Code Online (Sandbox Code Playgroud)

是否可以更改设置以缩短启动时间?

  • 我不需要在测试运行中保留索引,所以索引可以保存在内存中。我没有看到memory在上市6.4存储类型
  • 是否存在导致整个集群在不写入磁盘的情况下运行的设置(禁用日志记录、禁用文件存储、禁用 pid/状态)?
  • 集群将是单节点的,因此我可以禁用发现,但我还没有找到该设置。编辑:discovery.type=single-node在 6.4

elasticsearch

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

will_paginate报告的条目和页面太多

我正在使用will_paginate来显示从包含联接和select语句的查询返回的数据.当我对数据进行分页时,条目数等于执行select语句之前的条目数,即使在查询之后调用了paginate,并且查询包含的元素少于分页报告.

@sales = Sale.joins(:line_items).where(company_id: company_id, status: ['Complete', 'Voided'], time: (midnight_1..midnight_2)).order('id DESC')
puts @sales.length
Run Code Online (Sandbox Code Playgroud)

14

@sales = @sales.select('distinct sales.*')
puts @sales.length
Run Code Online (Sandbox Code Playgroud)

4

@sales.paginate(:per_page => 4, :page => params[page])
puts @sales.total_entries
Run Code Online (Sandbox Code Playgroud)

14

这导致显示指向空白页面的链接.

ruby-on-rails will-paginate

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

你能用vim做交互式宏或录音吗?

我想定义一个在特定时间打破用户输入的vim宏,这可能吗?

编辑:结果我记录(q),而不是宏

可以在录音中使用输入命令,但它比它的价值更麻烦.

我首先将插入输入转义映射到一个键

:map <F2> a<C-R>=input('input: ')<CR>
Run Code Online (Sandbox Code Playgroud)

然后我在q寄存器中进行了录音

name: 
Run Code Online (Sandbox Code Playgroud)

并将其粘贴到新标签中

iname: ^[
Run Code Online (Sandbox Code Playgroud)

在最后的逃脱后,我按下了<C-V><F2>这条线:

iname ^[^[OQ
Run Code Online (Sandbox Code Playgroud)

我猛拉回q缓冲区然后使用宏,让我使用输入函数.它很有效,但非常糟糕.

vim macros

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

为什么rails不会在运行之间重置测试数据库

rails代码库中有注释表明应该在运行之间重置测试数据库

耙-T

rake test:all                           # Run tests quickly by merging all types and not resetting db
rake test:all:db                        # Run tests quickly, but also reset db
Run Code Online (Sandbox Code Playgroud)

配置/ database.yml的

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
Run Code Online (Sandbox Code Playgroud)

对我来说,情况似乎并非如此.

我正在使用工厂女孩生成测试模型,这里是一个示例工厂

FactoryGirl.define do
  factory :podcast do
    sequence(:title)     { |n| "Podcast #{n}" }
    sequence(:feed_url)  { |n| "http://podcast.com/#{n}" …
Run Code Online (Sandbox Code Playgroud)

testing ruby-on-rails minitest factory-bot

5
推荐指数
2
解决办法
7034
查看次数

如何使用输入流实体而不是分块编码创建内容长度响应?

我需要从 Jersey 资源传输响应,但我不希望 http 响应使用Transfer-Encoding: chunked. 我提前知道流的长度,因此不需要分块编码。

    @GET
    @Path("/contentLength")
    public Response contentLength() {
        return Response.ok()
                .header("Content-Length", 10_000)
                .entity(RandomInputStream.generateBytes(10_000))
                .build());
    }
Run Code Online (Sandbox Code Playgroud)

即使我设置了 Content-Length,测试也显示响应使用分块传输编码

    @Test
    void contentLength() throws Exception {
        Response response = target().path("/contentLength").request().get();
        assertThat(response.getHeaderString("Transfer-Encoding"), Matchers.nullValue());
        assertThat(response.getHeaderString("Content-Length"), is("10000"));
    }
Run Code Online (Sandbox Code Playgroud)
Expected: null
     but: was "chunked"
Run Code Online (Sandbox Code Playgroud)

有类似的问题,但答案是错误的或需要缓冲响应,这对于大型响应来说是不可行的。对于大型响应,http 不需要分块编码,仅当响应启动时总长度未知时才需要分块编码。

jax-rs jersey jersey-2.0

5
推荐指数
0
解决办法
117
查看次数