小编gmi*_*ile的帖子

查询Rails中的条件

假设我们有两个表:"Items"和"Types".关系是:

item belongs_to type
type has_many items
Run Code Online (Sandbox Code Playgroud)

此外,Item表有一列,我们称之为"mark".什么是查询(如果可能的话,以Rails安全的方式)从中提取所有类型的类型表,它们在Items表中连接了带有"标记"的项目?

ruby-on-rails

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

Rails:列之间的验证

假设我们有一个模型,我们称之为文章。那里,我们有两列minmax。规则是:min不能大于或等于max。您如何解决这种自定义类型的验证?有任何想法吗?

更进一步,让我们假设我们有列charactermade_of。任务是创建一个验证,该验证将有助于避免“字符=人类”和“ made_of =钢铁”时的情况。

是否有标准的例程来管理列之间的“形而上”冲突?

validation ruby-on-rails

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

阵列优化:什么更贵?

以下哪些代码更贵?

x = my_array.inject {|sum,i| int+=i }
Run Code Online (Sandbox Code Playgroud)

要么

x = eval(my_array.join('+'))
Run Code Online (Sandbox Code Playgroud)

ruby arrays optimization

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

在测试纯Ruby程序时加载spec.opts

我正在为我的纯ruby程序编写规范,我想做的是以某种方式加载spec.opts我的测试套件.

我Rails我们可以创建一个相应的文件并将其放在spec应用程序的文件夹中.但是当我把一个spec.opts文件放在我的程序文件夹中时 - 魔法不起作用:)

我的动机是摆脱过往的选择,即

spec my_program_spec.rb -c -f s
Run Code Online (Sandbox Code Playgroud)

每次我跑spec命令.

ruby command-line rspec options

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

连接到远程节点

我在远程计算机上,它上面有一个正在运行的Erlang VM节点.我正在尝试连接到Erlang VM节点,iex但收到错误:

$ iex --name testing@127.0.0.1 --remsh myapp@127.0.0.1 --setcookie NMFJGSU0FwvGKlrqMuGfY1I6LtgSz1Rn2PLiDnqMS54
Erlang/OTP 18 [erts-7.3.1] [source] [64-bit] [async-threads:10] [kernel-poll:false]

Could not contact remote node myapp@127.0.0.1, reason: :nodedown. Aborting...
$
Run Code Online (Sandbox Code Playgroud)

epmd -names 报告Erlang VM节点正在运行:

$ epmd -names
epmd: up and running on port 4369 with data:
name myapp at port 45671
$ 
Run Code Online (Sandbox Code Playgroud)

以下vm.args是已部署应用的内容:

-name myapp@127.0.0.1
-setcookie NMFJGSU0FwvGKlrqMuGfY1I6LtgSz1Rn2PLiDnqMS54=
-smp auto
Run Code Online (Sandbox Code Playgroud)

问题:我做错了什么?

erlang remote-access elixir iex

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

与Array.min的复杂性

我有一个数组:

[0, 0, 0, 0, 0, 0, 0, 1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

我需要弄清楚最小元素的索引不是零.我怎么做?

ruby arrays

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

在Java中建立与数据库的持久连接

我在网上浏览了几个例子,发现每次我需要DB的东西,我都应该编写以下代码:

try
{
  // Step 1: Load the JDBC driver. 
  Class.forName("mysql_driver_name"); 
  // Step 2: Establish the connection to the database. 
  String url = "jdbc:string_to_mysql_server"; 
  Connection conn = DriverManager.getConnection(url,"user1","password");

  // fetch from the DB ...

}
catch (Exception e)
{
  System.err.println("Got an exception! "); 
  System.err.println(e.getMessage()); 
}
Run Code Online (Sandbox Code Playgroud)

每次我想要来自数据库的东西时都会提出这个代码是非常讨厌的,所以问题是 - 有没有办法在一开始就将我的所有应用程序完全连接到数据库,避免复制粘贴提到的代码,然后能够用DB 做我想做的一切吗?

我已经快速查看了NetBeans的Project菜单,但没有找到任何关于如何配置与所选DB的持久连接的线索.

如果它很重要,我正在编写一个纯桌面应用程序,即使用Java SE.此外,值得一提的是,我是Java的初学者.

java mysql database

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

应该在RSpec中

据我所知,should_receive仅适用于模拟对象.我想要检查,如果某个类(非对象)收到某个消息,如:

User.should_receive(:all).once
Run Code Online (Sandbox Code Playgroud)

我怎么做?

UPD.通常,为模型和控制器编写测试,我们可以编写User.should_receive(:smth).once.但在我的情况下,我正在测试lib文件夹中的任意类,不知怎的,我总是收到以下消息:

<User( [fields] ) (class)> expected :all with (no args) once, but received it 0 times>
Run Code Online (Sandbox Code Playgroud)

关于为什么会这样的任何想法?测试以某种方式查看User类,但无法检查它是否收到消息.当然,我已经十次检查发现该用户实际获得的消息.

message rspec ruby-on-rails class expectations

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

无法构建开源项目

我想为一个用go它构建的OSS项目做贡献,但我很难编译它.看起来好像我错过了一些明显的东西.

我认为这个问题与go我的计算机上安装的方式有关,而不是与项目本身有关,因此我在StackOverflow上发布它,而不是项目的"问题"部分.

以下是我正在做的事情.

  1. 我安装go使用homebrew:

    $ brew install go
    Updating Homebrew...
    ==> Auto-updated Homebrew!
    Updated 1 tap (homebrew/core).
    ==> Updated Formulae
    libebml
    
    ==> Downloading https://homebrew.bintray.com/bottles/go-1.8.3.sierra.bottle.tar.gz
    Already downloaded: /Users/gmile/Library/Caches/Homebrew/go-1.8.3.sierra.bottle.tar.gz
    ==> Pouring go-1.8.3.sierra.bottle.tar.gz
    ==> Caveats
    A valid GOPATH is required to use the `go get` command.
    If $GOPATH is not specified, $HOME/go will be used by default:
      https://golang.org/doc/code.html#GOPATH
    
    You may wish to add the GOROOT-based install location to your PATH:
      export PATH=$PATH:/usr/local/opt/go/libexec/bin
    ==> Summary
      /usr/local/Cellar/go/1.8.3: …
    Run Code Online (Sandbox Code Playgroud)

macos build go

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

如何在 gcp vm 中部署 docker 镜像

我正在尝试将容器化在 Docker 映像中的简单 R Shiny 应用程序部署到由 Google Cloud Platform 托管的虚拟机上,但我遇到了问题。

这些文件存储在 Github 存储库中,Docker 镜像是使用 GCP/ Cloud Build上的触发器构建的。Docker 文件基于rocker /shiny 格式。

构建被正确触发并开始构建,但构建在 10 分钟后一直超时。

TIMEOUT ERROR: context deadline exceeded
Run Code Online (Sandbox Code Playgroud)

是否有我可以添加到 Dockerfile 以延长构建时间的命令,还是我的 Dockerfile 错误?

r shiny docker dockerfile google-cloud-build

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