我想shared_examples在不同的规范文件中重用这个块。我想将其提取到一个单独的文件中,并传入对象,因此它并不总是用户的。我尝试的两种方法都失败了,这可能吗?
describe User do
before { @user = build_stubbed(:user) }
subject { @user }
shared_examples 'a required value' do |key| # trivial example, I know
it "can't be nil" do
@user.send("#{key}=", nil)
@user.should_not be_valid
end
end
describe 'name'
it_behaves_like 'a required value', :name
end
end
Run Code Online (Sandbox Code Playgroud) 我想在他们提供的日期和时间向不同时区的用户发送通知.我还没有实现任何东西,但我计划创建一个时间戳列并以UTC格式存储所有内容.在提交时,用户将选择一个时区,我将计算偏移量,将其添加到时间戳列,然后瞧.
我希望它很简单,但我的计划缺乏DST.我无法确定用户是否处于DST状态.
我该如何解决这个问题?我需要额外的列吗?有没有比我计划的更好的方法?
我正在尝试在请求完成后隐藏ajax加载程序,但done()回调在blur()事件发生后立即触发,然后才发出请求.我让我的控制器动作睡了5秒,以确保是这种情况,而且确实如此.我认为只有在结果从服务器返回后或5秒后才会触发.这是怎么回事?
$('#order_billing_post_code').on 'blur', ->
field = $(this)
post_code = field.val()
type = field.data 'address-type'
if post_code.length is 8
xhr = $.ajax
url: "/address_lookups/new"
data:
post_code: post_code
beforeSend: ->
field.siblings('i.address-ajax-loader').show()
success: (data) ->
parse data, type
dataType: "json"
xhr.done(
alert "done"
)
Run Code Online (Sandbox Code Playgroud) 我使用名为AntiSamy的工具(http://code.google.com/p/owaspantisamy/)来清理项目中的用户输入.我不懂Java.我只是创建对象,调用它的方法,它的工作原理.
最近该项目已在Google代码上更新,但下载包本身并未更新.我正在寻找有关如何下载更新代码以创建我自己的JAR文件并替换项目中现有文件的明确说明,从而使用更新.
看看谷歌代码中的代码分支,有很多文件夹和其他项目,所以我不确定我需要哪些部分,以及我应该具有哪种类型的目录结构.
任何人都知道JAR文件中应该包含什么/如何做到这一点?我不是一个经验丰富的编码员,所以请不要超级技术.
我有一个jQuery ajax函数,在调用失败时用HTML响应.如果调用成功,则以JSON响应:{"result":true}
$.ajax({
type: 'POST',
dataType: 'html',
success: function (response) {
if (response.RESULT === true) {
window.location.replace(baseUrl);
} // else do something else and show errors
}
});
Run Code Online (Sandbox Code Playgroud)
但是,Firefox不会识别JSON中的结果,因为dataType设置为'html'.我试着把它留空,这没用.是否有工作,或者返回两件事是不是很糟糕?
这是注册表格.我正在返回HTML,因为它更容易显示用户验证(服务器端)错误,而如果注册成功,我会重定向它们.
在每个循环中,我想输出一个HTML元素,如果它是循环的开头,或者索引是五的倍数.
- images.each do |image, index|
- if index == 1 || index == 5 || index == 10 || index == 15 # this is not scalable!
.row-fluid
.span2
div.image-wrapper
= image_tag image.url
Run Code Online (Sandbox Code Playgroud)
有没有更好的方式在Ruby中表达这一点?
我想在span2div中输出最多5 个row-fluiddiv.
我正在学习RSpec,我不禁注意到我的代码中有很多重复.以下只是其他许多例子中的两个例子.有没有办法创建共享测试而不必遍历每个属性?
describe "validation" do
describe "user_id" do
it "should not be blank or nil" do
@comment.user_id = nil
@comment.should_not be_valid
@comment.user_id = " "
@comment.should_not be_valid
end
it "should an integer" do
@comment.user_id = "a"
@comment.should_not be_valid
end
end
describe "post_id" do
it "should not be blank or nil" do
@comment.post_id = nil
@comment.should_not be_valid
@comment.post_id = " "
@comment.should_not be_valid
end
it "should an integer" do
@comment.post_id = "a"
@comment.should_not be_valid
end
end
end
Run Code Online (Sandbox Code Playgroud) How do I grab a hash from an array based on a value in the hash? In this case I want to select the hash that has the lowest score, being potato. I use Ruby 1.9.
[
{ name: "tomato", score: 9 },
{ name: "potato", score: 3 },
{ name: "carrot", score: 6 }
]
Run Code Online (Sandbox Code Playgroud) 每次我登录到我的VPS我必须运行source ~/.bashrc之前,我可以运行任何rvm,ruby或gem命令.
为什么是这样?默认情况下不能加载它?
ssh deployer@xxx
ruby -v
-bash: ruby: command not found
source ~/.bashrc
ruby -v
ruby 1.9.3p429 (2013-05-15 revision 40747) [i686-linux]
Run Code Online (Sandbox Code Playgroud)
我安装了rvm deployer.
我~/.bash_pofile有空的.我也有~/.profile以下内容:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH" …Run Code Online (Sandbox Code Playgroud)