刚开始使用Backbone.js.简单地包括Backbone(dev/production版本)会导致错误:
Uncaught TypeError: Cannot call method 'extend' of undefined 在128行:
// Attach all inheritable methods to the Model prototype
_.extend(Backbone.Model.prototype, Backbone.Events,
Run Code Online (Sandbox Code Playgroud) 我有一个简单的待办事项列表,所有都按预期呈现,但是当我点击编辑表单中的提交按钮时,表单被提交(GET/todo_items),页面被重新加载,只显示编辑表单."提交表单"事件没有受到约束,我无法弄清楚原因.我错过了什么?
App.Views.Edit = Backbone.View.extend({
events: {
"submit form": "save"
},
initialize: function(){
this.render();
},
save: function(){
var self = this;
var msg = this.model.isNew() ? 'Successfully created!' : 'Saved!';
this.model.save({
title: this.$('[name=title]').val(),
success: function(model, resp){
console.log('good');
new App.Views.Notice({message: msg});
self.model = model;
self.render();
self.delegateEvents();
Backbone.history.saveLocation('todo_items/'+ model.id);
$('#edit_area').html('');
},
error: function(){
console.log('bad');
new App.Views.Error();
}
});
return false;
},
render: function(){
$('#edit_area').html(ich.edit_form(this.model.toJSON()));
}
});
Run Code Online (Sandbox Code Playgroud)
这是编辑表格:
<script id="edit_form" type="text/html">
<form>
<label for="title">Title:</label>
<input name="title" type="text" value="{{title}}" />
<button>Save</button>
</form>
</script>
Run Code Online (Sandbox Code Playgroud) 不可否认,我是Nokogiri的新手,我必须遗漏一些东西......
我只是试图从这个XML中打印作者> name节点:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:gd="http://schemas.google.com/g/2005" xmlns:docs="http://schemas.google.com/docs/2007" xmlns="http://www.w3.org/2005/Atom" gd:etag="">
<category term="http://schemas.google.com/docs/2007#document" scheme="http://schemas.google.com/g/2005#kind"/>
<author>
<name>Matt</name>
<email>Darby</email>
</author>
<title>Title</title>
</entry>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用它,但它什么都没打印.看似没有节点(甚至'*')什么都不返回.
Nokogiri::XML(@xml_string).xpath("//author/name").each do |node|
puts node
end
Run Code Online (Sandbox Code Playgroud) 确保在Controller操作中生成正确的RJS的最佳方法是什么?
例如,我想确保div被突出显示为:
def new
render :update do |page|
page.visual_effect :highlight, :some_div
end
end
Run Code Online (Sandbox Code Playgroud)
Rant: 这很快成为我使用RSpec一年后厌倦RSpec的原因之一.这应该是一个简单的问题,但是没有人似乎有答案.
我一再被告知RSpec指定行为,我在这里尝试做的只是"测试代码".突出显示:some_div就是我所知道的行为.
如果我在rails项目中,使用rails.vim进行编辑,我该如何获得:通过Spork运行规范?
它主要只是一个问题:通过"-o"标志Rake知道项目的specs/spec.opts文件?
在我的办公室,我们有一个像这样的网络目录结构:
/jobs/2004/3999-job_name/...
/jobs/2004/4000-job_name/...
Run Code Online (Sandbox Code Playgroud)
问题是员工重命名"4000-job_name"文件夹(这反过来又打破了依赖于名称与数据库一致的其他事物).
如何阻止用户重命名父文件夹,同时仍允许他们完全控制该文件夹的内容?
请记住,这是Windows用户将访问的Samba共享.
假设我有一个名为Preview的Metal类.如何使用RSpec进行测试?
当我尝试:
require 'spec_helper'
describe Preview do
it "should return the posted content" do
post "/preview", :content => "*title*"
response.body.should == "*title*"
end
end
Run Code Online (Sandbox Code Playgroud)
我明白了:
undefined method `post' for #<ActiveSupport::TestCase::Subclass_1:0x1058b3098>
Run Code Online (Sandbox Code Playgroud)
:post如果测试没有显式用于Controller ,RSpec似乎没有加载该方法.我试过指定:type => :controller无济于事.
我使用cache-money gem来透明地使用Memcached.使用提供的配置文件,它在所有模式(开发,测试,生产)上启用.有没有办法只在生产模式下激活缓存资金?
目前还不清楚如何做到这一点,并且在开发模式下处理缓存是一个彻底的痛苦.