我正在使用Postgres的本机数组类型,并尝试查找ID不在数组收件人ID中的记录.
我可以找到他们在哪里IN:
SELECT COUNT(*) FROM messages WHERE (3 = ANY (recipient_ids))
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
SELECT COUNT(*) FROM messages WHERE (3 != ANY (recipient_ids))
SELECT COUNT(*) FROM messages WHERE (3 = NOT ANY (recipient_ids))
Run Code Online (Sandbox Code Playgroud)
测试这种情况的正确方法是什么?
我正在将应用程序升级到Rails 3.我们有一个类似以下的应用程序控制器:
class ApplicationController < ActionController::Base
helper_method :current_user
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
Run Code Online (Sandbox Code Playgroud)
因为我们定义了"helper_method",所以所有视图都可以使用"current_user".它可供控制器使用,因为它们都继承自ApplicationController类.
但是,当我们使用2.3.8时,通过模型可以访问"current_user",但现在却没有.有没有办法让这个暴露在模型中?
window.User = Backbone.Model.extend({
defaults: {
name: 'Jane',
friends: []
},
urlRoot: "users",
initialize: function(){
this.fetch();
}
});
var HomeView = Backbone.View.extend({
el: '#container',
template: _.template($("#home-template").html()),
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
home: function() {
var user = new User({id: 1});
this.homeView = new HomeView({
model: user
});
this.homeView.render();
},
Run Code Online (Sandbox Code Playgroud)
正在查询模型数据,并且根级别属性工作正常,但是包含其他对象数组的属性似乎不会显示.
模板:
<script id="home-template" type="text/template">
<div id="id">
<div class="name"><%= name %></div>
<br />
<h3> Single Friends</h3>
<br />
<ul data-role="listview" data-inset="true", data-filter="true">
<% _.each(friends, function(friend) { %>
<li>
<a …Run Code Online (Sandbox Code Playgroud) 我有一个Modular Sinatra应用程序,我正在尝试将Bootstrap添加到应用程序中.
get '/bootstrap/application.css' do
less :"bootstrap/bootstrap"
end
Run Code Online (Sandbox Code Playgroud)
我在views/bootstrap中拥有的文件更少,包括bootstrap.less.
我收到此错误:
Less::ParseError at /bootstrap/application.css 'reset.less' wasn't found.
Run Code Online (Sandbox Code Playgroud)
Bootstrap.less的第一个真正的路线是:
// CSS Reset
@import "reset.less";
Run Code Online (Sandbox Code Playgroud)
我尝试了所有不同的路径格式,但它从未找到要导入的文件.知道如何使这项工作?
只是好奇,假设设置了attr_accessor,从类中访问实例变量的最佳实践是什么.
class Test
attr_accessor :user
def initializer(user)
@user = user
end
def foo
@user
end
end
Run Code Online (Sandbox Code Playgroud)
要么
class Test
attr_accessor :user
def initializer(user)
@user = user
end
def foo
self.user
end
end
Run Code Online (Sandbox Code Playgroud)
那么通过实例变量(@user)或getter方法(Test#user)?
我们有一些看起来像这样的嵌入式文档:
{
"_id" : ObjectId("4e402353bc9f6ec5a6000001"),
"first_name" : "Chris",
"last_name" : "Jones",
"alerts" : [
{
"_id" : ObjectId("4f7cd6ffc067db00070022d4"),
"name" : "Default",
"email_frequency" : "weekly",
"interested_industries" : [
"Computer Software",
"Internet"
],
"interested_employers" : [
"Facebook",
"AOL"
],
"interested_skills" : [ ],
"matches" : [
ObjectId("4ee46a2a0dd0c70017000365"),
ObjectId("4efa1707bacfa40001012b65"),
ObjectId("4e402376bc9f6ec5a6000a7a"),
ObjectId("4e4e0eb8d052fc4028021f66"),
ObjectId("4ee55d8500ca410014000003"),
ObjectId("4ee63d06d96b850001008688"),
ObjectId("4e57be7ed052fc606a002335"),
ObjectId("4f05d47d9ce340001702ba42"),
ObjectId("4f200ffcaf5f34000e0021a4"),
ObjectId("4e4de701d052fc33da00052f")
],
"updated_at" : ISODate("2012-05-03T18:26:14.774Z")
}
]
}
Run Code Online (Sandbox Code Playgroud)
由于上面的文档包含在一个数组中,我无法从选择器中选择它,如下所示:
User.collection.update({"_id" => user.id}, {:$set => {"alert.matches" => matches}})
Run Code Online (Sandbox Code Playgroud)
但这将更新所有#alerts匹配.我只想用ID"4fa7fd60e5be08bcc9000644"更新一个警报.
在某些Rails视图中,我们具有javascript函数,这些函数可以异步加载某些数据以填充页面。我们的application.js文件将所有JavaScript加载到asset / javascripts文件夹中。
这是我们的haml视图之一:
:javascript
$(function() {
fetch_all_facebook_invitees();
});
Run Code Online (Sandbox Code Playgroud)
如果我们将fetch_all_facebook_invitees函数定义放在coffeescript文件中,则会在每个页面上加载它,因为它们已包含在应用程序的所有页面中:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
加载页面的JavaScript的最佳做法是什么?仅选择性地这样做而不加载整个树?
我的网站上有AdSense横幅广告.它是由他们给我的代码片段开始的.
在我的应用程序的另一部分,我弹出一个模式,其中包含一些信息.我想在该模式中显示另一个广告单元.我在该模态中定义了以下内容:
<script type="text/javascript"><!--
google_ad_slot = "xxxxx";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Run Code Online (Sandbox Code Playgroud)
什么都没发生.我必须再次包含"show_ads.js"文件,这很奇怪.此外,它似乎会覆盖主模块上的全局js变量.
任何想法如何使这项工作?
只是想知道为什么这样做:
window.NewListView = Backbone.View.extend({
template: _.template('<a href="/list" class="button new-list">Create New List</a>'),
render: function(){
$(this.el).html(this.template());
return this;
}
});
window.List = new (Backbone.Router.extend({
routes: { "": "index" },
initialize: function(){
this.newListView = new NewListView();
},
start: function(){
Backbone.history.start();
},
index: function(){
$('.lists').append(this.newListView.render().el);
}
}));
$(function(){ List.start(); })
Run Code Online (Sandbox Code Playgroud)
而这不是:
window.NewListView = Backbone.View.extend({
template: _.template('<a href="/list" class="button new-list">Create New List</a>'),
render: function(){
$(this.el).html(this.template());
return this;
}
});
window.List = new (Backbone.Router.extend({
routes: { "": "index" },
initialize: function(){
this.newListView = new NewListView();
$('.lists').append(this.newListView.render().el); …Run Code Online (Sandbox Code Playgroud) ruby ×3
backbone.js ×2
javascript ×2
adsense ×1
arrays ×1
coffeescript ×1
haml ×1
json ×1
mongodb ×1
postgresql ×1
sinatra ×1