25

我收到了insert failed: Method not found日志消息,它可能是这些线程中描述的结果:

但是,我不知道如何。让我展示代码,希望能更清楚地解释。我正在使用咖啡脚本:

if Meteor.isClient
  @VINs = new Meteor.Collection("vins")

  scoped_vins = @VINs
  Template.vins.events =
    "click .icon-plus-sign": ->
      console.log "this is #{this}"
      realVIN = $("#your-vin").val().replace /\D/g, ''
      console.log "user id is: #{Meteor.userId()} vin is #{parseInt(realVIN)}"
      VINs.insert number: parseInt(realVIN), owner: Meteor.userId() if Meteor.userId()
      $("#your-vin").val('')
else
  @VINs = new Meteor.Collection("vins")

我完全是流星的 n00b,但我从上面引用的线程中收集到的是,该集合必须在客户端和服务器上可用。这不是我所做的,还是我正在发展咖啡盲?

谢谢!

4

1 回答 1

41

确保您还在服务器和客户端上声明了您的集合。

在上面@VINs = new Meteor.Collection("vins")的客户端和服务器中的代码中,您将代码放入/client目录中可能是什么?

如果是这样,这意味着代码将仅在客户端上运行,即使您有elseforif Meteor.isClient块。

要纠正此问题,请将您使用的行复制到目录中的.coffee文件中/server

@VINs = new Meteor.Collection("vins")
于 2013-08-29T18:43:08.197 回答