我想更新一个文档的_id MongoDB.我知道这不是一个非常好的实践.但由于某些技术原因,我需要更新它.但如果我尝试更新它,我有:
> db.clients.update({ _id: ObjectId("123")}, { $set: { _id: ObjectId("456")}})
Performing an update on the path '_id' would modify the immutable field '_id'
Run Code Online (Sandbox Code Playgroud)
而且没有更新.我怎么能真正更新它?
好的,所以我有这个哈希
h
=> {"67676.mpa"=>{:link=>"pool/sdafdsaff", :size=>4556}}
> h.each do |key, value|
> puts key
> puts value
> end
67676.mpa
linkpool/sdafdsaffsize4556
Run Code Online (Sandbox Code Playgroud)
我如何访问循环中值哈希值中的单独值
Windows回车\r\n是\n在Unix中,被\r\n视为两个字符?
我正在寻找在Rails 3中生成Feed的最佳实践/标准模式.http://railscasts.com/episodes/87-generating-rss-feeds仍然有效吗?
我希望能够在OSX中使用Vagrant之外的docker.现在这是不可能的.导致它不仅仅限于Linux安装的具体原因是什么?
我可以检查是否在用户类中调用了FeedItem :: populate_from_friend_to_user?
it "should auto populate feed after user.add_friend" do
@user.add_friend(@friend1)
@user.should_receive('FeedItem::populate_from_friend_to_user').with(@friend1, @user)
end
Run Code Online (Sandbox Code Playgroud)
通过上面的代码我得到:
undefined method `populate_from_friend_to_user' for :FeedItem:Symbol
Run Code Online (Sandbox Code Playgroud) 所以,我们一直在建立attr_accessible并attr_protected通过了我们的Rails应用程序3.2多领域.目前我们确实没有测试以确保这些字段受到保护.
所以我决定谷歌一些答案,并偶然发现这个解决方案:
RSpec::Matchers.define :be_accessible do |attribute|
match do |response|
response.send("#{attribute}=", :foo)
response.send("#{attribute}").eql? :foo
end
description { "be accessible :#{attribute}" }
failure_message_for_should { ":#{attribute} should be accessible" }
failure_message_for_should_not { ":#{attribute} should not be accessible" }
end
Run Code Online (Sandbox Code Playgroud)
但是这个解决方案只测试方法是否响应.我需要的是一种方法,让我测试属性可以和不能被大量分配.老实说,我喜欢这种语法
it { should_not be_accessible :field_name }
it { should be_accessible :some_field }
Run Code Online (Sandbox Code Playgroud)
有没有人有更好的解决方案来解决这个问题?
我想用JSON中的响应发出Ajax请求.所以我提出了这个Ajax请求:
$.ajax({
url: 'http://my_url',
dataType: "json",
success: function(data){
alert('success');
},
error: function(data){
alert('error');
},
complete: function(data) {
alert('complete')
}})
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,但是当我的网址发送给我一个HTTP代码404时,没有使用回调,甚至是完整的回调.经过研究,这是因为我的dataType是'json'所以404返回是HTML并且JSON解析失败了.所以没有回调.
有一个解决方案,当404被引发时调用回调函数?
编辑:完成回调不调用返回是404.如果你想要一个URL机智404你可以打电话:http://twitter.com/status/user_timeline/jksqdlmjmsd.json?count = 3& callback = jsonp1269278524295&_ = 1269278536697这是这个网址我有我的问题.
它们似乎无法从ActionView :: TestCase访问