在Ruby中有没有办法将所有数组元素组合成一个字符串?
示例数组:
@arr = ['<p>Hello World</p>', '<p>This is a test</p>']
Run Code Online (Sandbox Code Playgroud)
示例输出:
<p>Hello World</p><p>This is a test</p>
Run Code Online (Sandbox Code Playgroud) 我试图使用以下代码比较两个Ruby Hashes:
#!/usr/bin/env ruby
require "yaml"
require "active_support"
file1 = YAML::load(File.open('./en_20110207.yml'))
file2 = YAML::load(File.open('./locales/en.yml'))
arr = []
file1.select { |k,v|
file2.select { |k2, v2|
arr << "#{v2}" if "#{v}" != "#{v2}"
}
}
puts arr
Run Code Online (Sandbox Code Playgroud)
屏幕输出是file2的完整文件.我知道文件不同的事实,但脚本似乎没有拿起它.
我需要在我的Rails脚本中将列类型从text更改为longtext,但无法找到有关如何执行此操作的任何内容.
有没有人碰过这个?
谢谢!丹尼斯
我试图确定如果用户使用jQuery删除已在textarea中预先填充的内容,textarea是否为空.
无论如何要做到这一点?
这就是我所拥有的,而且它不起作用
$(textarea).live('change', function(){
if($(this).val().length == 0) {
$(submitButtonClass).addClass('disabled_button');
$(submitButtonClass).removeClass('transSubmit');
} else {
$('.disabled_button').addClass('transSubmit').css({
'cursor':'pointer'
}).removeClass('disabled_button');
}
});
Run Code Online (Sandbox Code Playgroud) 我正在使用ajax为我的注册提交表单,但是在尝试设置工具提示以显示从控制器返回的错误的错误消息时遇到问题.
JavaScript的:
$(document).on('ajax:success', '.user_modal_form', function(e, data, status, xhr) {
var context;
context = $(this);
if (data.success) {
$('button', context).hide();
$('.spinner', context).show();
location.reload();
} else {
if (data.errors != null) {
$.each(data.errors, function(key, error) {
var field;
field = $("#athlete_" + key);
field.attr('data-original-title', "" + key + " " + error).tooltip({
trigger: 'manual'
}).tooltip("show");
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
错误信息: Uncaught Error: no such method 'show' for tooltip widget instance
jquery twitter-bootstrap twitter-bootstrap-rails twitter-bootstrap-tooltip
我在Heroku上使用Postgres,我需要从生产数据库中转储一个表并将其转储到我的暂存数据库中.我安装了heroku工具带,但不知道如何转储单个db表以导入到我的staging db中.
我正在使用rspec-sidekiqgem(https://github.com/philostler/rspec-sidekiq)帮助测试我正在编写的工作人员,但出于某种原因,我的测试仍然失败.
这是我的测试:
require 'spec_helper'
describe CommunicationWorker do
it { should be_retryable false }
it "enqueues a communication worker" do
subject.perform("foo@bar.com", "bar@foo.com", [1,2,3])
expect(CommunicationWorker).to have_enqueued_jobs(1)
end
end
Run Code Online (Sandbox Code Playgroud)
这是错误:
1) CommunicationWorker enqueues a communication worker
Failure/Error: expect(CommunicationWorker).to have_enqueued_jobs(1)
expected CommunicationWorker to have 1 enqueued job but got 0
# ./spec/workers/communication_worker_spec.rb:9:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
我将他们的低级别测试基于他们的维基上的示例,但它不适合我...任何理由为什么这不起作用?
我正在开发一个需要根据以下条件验证密码的Rails 3应用程序: must be at least 6 characters and include one number and one letter.
这是我的正则表达式:
validates :password, :format => {:with => /^[([a-z]|[A-Z])0-9_-]{6,40}$/, message: "must be at least 6 characters and include one number and one letter."}
Run Code Online (Sandbox Code Playgroud)
现在,如果我输入密码(例如:dogfood)它将通过.但我需要做的是通过上述标准.
我在正则表达式方面并不是那么出色,所以非常感谢任何帮助!
我正在尝试为使用aws-sdkNPM模块的应用程序编写一些测试覆盖,该模块将事物推送到SQS队列,但我不确定如何正确地模拟事物.
这是我到目前为止的测试:
var request = require('superagent'),
expect = require('chai').expect,
assert = require('chai').assert,
sinon = require('sinon'),
AWS = require('aws-sdk'),
app = require("../../../../app");
describe("Activities", function () {
describe("POST /activities", function () {
beforeEach(function(done) {
sinon.stub(AWS.SQS.prototype, 'sendMessage');
done();
});
afterEach(function(done) {
AWS.SQS.prototype.sendMessage.restore();
done();
});
it("should call SQS successfully", function (done) {
var body = {
"custom_activity_node_id" : "1562",
"campaign_id" : "318"
};
reqest
.post('/v1/user/123/custom_activity')
.send(body)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(res.status).to.equal(200)
assert(AWS.SQS.sendMessage.calledOnce);
assert(AWS.SQS.sendMessage.calledWith(body));
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
我看到的错误是:
1) Activities POST …Run Code Online (Sandbox Code Playgroud) ruby ×3
jquery ×2
aws-sdk ×1
hash ×1
heroku ×1
migration ×1
node.js ×1
postgresql ×1
regex ×1
rspec ×1
rspec-rails ×1
sidekiq ×1
sinon ×1
validation ×1