小编nde*_*eau的帖子

rails find_or_initialize关系

当我创建一个新用户时,为了避免重复,我使用find_or_initialize方法:

user = find_or_initialize_by_email(the_email)
Run Code Online (Sandbox Code Playgroud)

如果此用户是与相关公司一起创建的,我如何避免公司中的重复项?

我可以这样做:

find_or_initialize_by_email_and_by_company_name(the_email, the_company_name)
Run Code Online (Sandbox Code Playgroud)

谢谢!

activerecord ruby-on-rails

4
推荐指数
1
解决办法
3517
查看次数

css hover嵌套类传播

我知道这是一个经典的但我在网上找不到答案:

我有这个HTML代码:

<div class="comment>
  <div class="myLinks">Some Links</div>
  <div class="comment">
    <div class="myLinks">Some Links</div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

然后我有这个CSS(用scss编写):

.myLinks {
  display: hidden;
}

.comment {
  &:hover {
    .myLinks {
      display: visible;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

当指针位于第一个注释块之上时,嵌套的一个悬停效果也会被激活.我想要的是我的链接只在徘徊的评论中可见,而不是在他的父母或孩子中.

我怎样才能做到这一点?谢谢!

css nested hover propagation

4
推荐指数
1
解决办法
1万
查看次数

jquery ui自动完成如何加载默认值列表

非常简单的问题(但我无法在网上找到答案......):我有一个自动完成字段以这种方式设置:

$(document).ready ->
         $('#projecttask_user_name').autocomplete
                 source: "/autocomplete/users"
Run Code Online (Sandbox Code Playgroud)

我希望jquery在我选择字段时触发源,以便获得完整的可能性列表,即使我没有在字段中输入任何内容.

我怎样才能做到这一点?谢谢!

jquery-ui autocomplete jquery-ui-autocomplete

3
推荐指数
1
解决办法
2545
查看次数

Meteor autoform simple-schema:如何自定义验证消息?

我有这个架构:

Users = new Meteor.Collection('users', {
    schema: {
        firstname: {
            type: String,
            label: "First name",
            max:50
        },
        lastname: {
            type: String,
            label: "Last name",
            max:50
        },
        email: {
            type: String,
            label: "E-mail",
            regEx: SimpleSchema.RegEx.Email,
            optional: false,
            max:50
        },
        tel: {
            type: String,
            label: "Phone",
            optional: false,
            max:50
        },
        zip: {
            type: String,
            label: "Zip code",
            optional: false,
            regEx: /^[0-9]{5}$/,
            max:50
        },
        city: {
            type: String,
            label: "City",
            optional: false,
            max:50
        },
    }
});
Run Code Online (Sandbox Code Playgroud)

在我的模板中,我像这样使用Autoform:

<template name="userSubmit">
    {{> quickForm collection="Users" id="insertUserForm" …
Run Code Online (Sandbox Code Playgroud)

validation node.js meteor meteor-autoform

3
推荐指数
1
解决办法
4915
查看次数

Meteorjs Mongodb如何用momentjs查询日期

在Meteor中,我以这种方式创建了一个获胜者文档:

var winner = {
                participant_id: array[randomIndex]["_id"], //don't worry about the array[randomIndex]
                creation_date: new Date()
            };
id = Winners.insert(winner);
Run Code Online (Sandbox Code Playgroud)

后来,我想知道今天有多少获奖者.我尝试了很多方法,但是我无法获得正确的结果.

我尝试的最后一件事是这一件事:

Winners.find({creation_date: {"$gte": moment().startOf('day'), "$lt": moment().add('days',1)}}).count();
Run Code Online (Sandbox Code Playgroud)

但结果总是等于零.

我想原因是moment().startOf('day')不是日期对象,但我不知道如何以正确的方式查询它.

mongodb meteor momentjs

3
推荐指数
1
解决办法
3414
查看次数

为什么setTimeout不能用于AJAX请求?

我有这个非常简单的jQuery函数:

$(".milestone-in-tree").live({
    mouseenter: function() {
        setTimeout(
        $.ajax({
            type: "GET",
            url:"/projects/pmnodes/" + $(this).data("pmnode") + "/addbuttons.js"
        }),5000)
    },
    mouseleave: function() {
        $(".grid-btn").delay(800).remove();
    }
});
Run Code Online (Sandbox Code Playgroud)

我想让它在将AJAX请求发送到服务器之前等待5秒,但它不会等待,它只是立即发送它.为什么?

更新:

感谢您的所有反馈.我改变了所有答案中建议的功能:

$(".milestone-in-tree").live({
    mouseenter: function() {
        var node = $(this).data("pmnode")
        setTimeout(function() {
        $.ajax({
            type: "GET",
            url:"/projects/pmnodes/" + node + "/addbuttons.js"
        }),5000});
    },
    mouseleave: function() {
        $(".grid-btn").delay(800).remove();
    }
});
Run Code Online (Sandbox Code Playgroud)

但我仍然没有延迟.有什么我误解了吗?PS:我创建了节点变量,因为我忽略了一个原因,在SetTimeout匿名函数内不再可以访问$(this).

更新2

最后,我可以设法得到延迟,但我意识到在延迟后仍然将请求发送到服务器,即使在两者之间触发了mouseleave事件......

我可以找到一个解决方法.这是完全不同的.延迟不再起作用,但ajax请求在mouseleave事件中被中止,这是我真正需要的.对于可能感兴趣的人,这是代码:

var button_request;
$(".milestone-in-tree").live({
    mouseover: function() {
        var node = $(this).data("pmnode");
        button_request = $.ajax({
                        type: "GET",
                        url:"/projects/pmnodes/" + node + "/addbuttons.js"
                    });
        setTimeout(function() {button_request;},5000)
    },
    mouseleave: …
Run Code Online (Sandbox Code Playgroud)

ajax jquery wait

2
推荐指数
3
解决办法
8184
查看次数

collectionFS:图像未定义

我是第一次使用默认模式尝试collectionFS(v 0.4.3)但没有运气:

我在/ models:collection_fs.js中创建了一个文件

var Images = new FS.Collection("images", {
    stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});
Run Code Online (Sandbox Code Playgroud)

然后我在表单事件中添加了一个模板:upload_form.coffee

Template.uploadForm.events "change .myFileInput": (event, template) ->
  FS.Utility.eachFile event, (file) ->
    Images.insert file, (err, fileObj) ->
Run Code Online (Sandbox Code Playgroud)

但它一直告诉我:

Uncaught ReferenceError: Images is not defined
Run Code Online (Sandbox Code Playgroud)

我知道collection_fs.js运行(使用console.log检查).如果我没有错,前面带var的变量具有全局范围.所以我不明白什么是错的.

谢谢!

meteor

2
推荐指数
1
解决办法
707
查看次数

rails 集成测试为什么是fixtures而不是db

我是在 Rails 中测试的新手,我不明白为什么或何时应该使用夹具(或工厂),而不仅仅是为我的测试数据库播种并查询它来运行测试?

在许多情况下,在 dev 和 test env 中拥有相同的数据应该更快、更容易。

例如,如果我想测试一个索引页,我应该通过工厂创建 100 条记录还是应该用 100 条记录为数据库做种子?

我有人可以澄清这一点,这会很棒。

谢谢!

testing integration-testing ruby-on-rails capybara

1
推荐指数
1
解决办法
474
查看次数

rails sum多个字段

我试图在rails中做这个假设简单的操作:

self.timesheets.select("sum(total) as total, sum(quantity) as quantity").first where self is a project
Run Code Online (Sandbox Code Playgroud)

当我在控制台模式下执行它时,它可以工作,但它呈现3列:

[#<Timesheet id: nil, quantity: 120.1, total: 6245.2>]
Run Code Online (Sandbox Code Playgroud)

当我在应用程序中运行它时,我收到以下错误消息:

PG::GroupingError - ERROR:  column "timesheets.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ..."  WHERE "timesheets"."project_id" = $1  ORDER BY "timesheet...
                                                             ^
:
  activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:811:in `prepare_statement'
  activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `exec_cache'
  schema_plus (1.3.1) lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb:231:in `exec_cache_with_schema_plus'
  activerecord (4.0.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:139:in `block in exec_query'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'
  activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument' …
Run Code Online (Sandbox Code Playgroud)

sql activerecord grouping ruby-on-rails

1
推荐指数
1
解决办法
3689
查看次数

meteor logginbutons如何禁用注册

我在我的应用程序中使用Meteor的logginButtons.

我想删除注册的能力.

是不是有一个我可以编辑的配置来做到这一点?

我可以调整css,但它不是很干净......

meteor

1
推荐指数
1
解决办法
938
查看次数