我的Ruby控制器中有以下代码:
mastertest_controller.rb
def index
......
@mastertest = connection.execute("select code_ver from mastertest")
result_array = { sometihng }
......
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @mastertest}
format.json { render :json => result_array}
end
Run Code Online (Sandbox Code Playgroud)
但它只允许我访问@mastertest视图(index.html.erb).如何将数组传递给视图???
我在Ruby中有一个数组,其值如下
xs = %w(2.0.0.1
2.0.0.6
2.0.1.10
2.0.1.5
2.0.0.8)
Run Code Online (Sandbox Code Playgroud)
等等.我想对数组进行排序,以便最终结果应该是这样的:
ys = %w(2.0.0.1
2.0.0.6
2.0.0.8
2.0.1.5
2.0.1.10)
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用该array.sort功能,但它"2.0.1.10"之前放置过"2.0.1.5".我不确定为什么会这样
以下是我使用JenkinsAPI for Python进行的操作
# Python scipt to get build information
# Import jenkins API and check Jenkins Version
import jenkinsapi
from jenkinsapi.jenkins import Jenkins
from jenkinsapi.build import Build
J = Jenkins('http://test.com')
job = J['MY_JOB_NAME']
print "Jenkins version:", J.version, "\n"
print jenkinsapi.api.get_latest_test_results('http://test.com','MY_JOB_NAME'), "\n"
B= Build('http://test.com',22,job)
print B.get_resultset()
Run Code Online (Sandbox Code Playgroud)
我一直收到这个我无法理解的错误:
Traceback (most recent call last):
File "myscript.py", line 19, in <module>
print B
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.2.18-py2.7.egg/jenkinsapi/build.py", line 49, in __str__
return self._data['fullDisplayName']
KeyError: 'fullDisplayName'
svikani@myunix:~$ python myscript.py
Traceback (most recent call last):
File "myscript.py", …Run Code Online (Sandbox Code Playgroud) 我从我的数据库中得到一个纪元字符串,它看起来像这样:1391328000000
我很难将其转换为 Java 日期。
我尝试了以下方法:
private String buildDate(String dateString){
System.out.println("dateString " + dateString);
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
String formatted = format.format(Integer.parseInt(dateString));
return formatted;
}
Run Code Online (Sandbox Code Playgroud) 我有一个文本文件,如下所示:
/* 0 */
{
"_id" : ObjectId("abcd")
}
/* 1 */
{
"_id" : ObjectId("432432")
}
/* 2 */
{
"_id" : ObjectId("32132121")
}
/* 3 */
{
"_id" : ObjectId("321312")
}
Run Code Online (Sandbox Code Playgroud)
我想从文件中只提取ObjectId.
我的输出应该是这样的:
abcd
432432
32132121
321312
Run Code Online (Sandbox Code Playgroud)
如果我使用grep或awk,它的正确shell脚本是什么?
我在我的ROR应用程序中的html.erb文件中有以下代码.
<% $tmp_bug="something" %>
<a href="http://jira.copivia.com:8080/browse/#{$tmp_bug}">JIRA</a>
Run Code Online (Sandbox Code Playgroud)
我想将该ruby变量添加到超链接的末尾.这似乎不起作用.
我想删除所有在具有多个子目录的目录中以'〜'结尾的文件.
有没有安全的方法来做到这一点?
我有一个mongo集合,其文档如下所示:
{
"_id" : ObjectId("9873214jkhdkfjdsf8324"),
"nm" : "test",
"sts" : 1,
"updby" : NumberLong(0),
"tags" : [
{
"name" : "women",
"rank" : 1,
"type" : 3
},
{
"name" : "men",
"rank" : 1
},
{
"name" : "clothing",
"rank" : 2,
"type" : 1
}
]
Run Code Online (Sandbox Code Playgroud)
}
我想查询集合,以便我想要所有具有"名称"的文档:"women"和"type":3在返回的每个文档的tags子文档中.
我知道mongo查询应该是这样的:
db.collection.find("tags":{
$all:[
{"$elemMatch":{"name":"women","type":3}},
]})
Run Code Online (Sandbox Code Playgroud)
我尝试使用morphia提供的'hasthiselement',但我无法形成我想要的确切查询.
getMongoDAORead().getDatastore().createQuery(test.class)
.field("tags").hasThisElement("name").equal("women");
Run Code Online (Sandbox Code Playgroud)
此查询似乎不正确.有人可以帮我形成正确的查询吗?
我有一些带有一些键值对的哈希,如下所示:
@level2 = @l2.inject(Hash.new(0)) { |hash,element|
hash[element] +=1
hash }
Run Code Online (Sandbox Code Playgroud)
我根据键对哈希进行一些排序.
@level2 = @level2.sort_by { |x, _| x }.reverse
Run Code Online (Sandbox Code Playgroud)
现在我假设sort_by给了我一个数组数组.我想将其拆分为2个数组,这样我的第一个数组应包含所有键,第二个数组应包含所有值.
排序哈希后无法访问哈希#键和哈希#值.所以这在这种情况下不起作用.