0
votes

I'm trying to learn Meteor and coffeescript, but I'm stuck while trying to learn meteor methods calls. I wrote the following code:

client/views/home/home.html

  <template name="home">
     Welcome to my new meteor app
     <input type="button" id='createFile' value="createFile" />
  </template>

client/views/home/home.coffee

Template.home.events
'click #createFile': ->
    Meteor.call 'alwaystrue', (error, result) ->
        console.log error
        console.log result
        return

    console.log 'You pressed the button'  if typeof console isnt 'undefined'
    return

server/metodi.coffee

Meteor.methods
 alwaystrue: -> 
  true

The button when clicked should call a server method from the client, using Meteor.call , but it says that the alwaystrue method is not found.

What am I doing wrong? why my code cant see the methods?

I'm starting from this boilerplate: https://github.com/Differential/meteor-boilerplate , whit the latest node.js/meteor, on the latest ubuntu (14.04).

1
I don't see anything technically wrong here - it seems like something outside of the question is screwed up. e.g. a file isn't saved, the methods file doesn't actually end in .coffee and isn't being compiled, the method name is misspelled, etc. - David Weldon
I'll check harder now - Mascarpone
Yes It works. After recreating from scratch without using the boilerplate I made it work. I might think it was due to indentation or some packages installed. Thank you very very much for your moral support, please rephrase your comment as an answer so I can elect it as the right suggestion. - Mascarpone

1 Answers

1
votes

After careful inspection, I don't see anything wrong with the code which leads me to believe something outside of the question is messed up. Try things like:

  • Make sure all files are saved.
  • Make sure all of the CoffeeScript files actually end in .coffee.
  • Check that the method name is spelled correctly in all cases.

If all else fails, you can create a separate project and just add this code to validate it.

Style note - CoffeeScript has implicit returns, so unless you really want to return undefined or you want to return early from a function, you don't need the explicit return statements in Template.home.events.