dnagir / knockout-rails

KnockoutJS for Rails with Sweetness
97 stars 16 forks source link

knockout model not being defined #4

Closed amalagaura closed 12 years ago

amalagaura commented 12 years ago

Improved the asset pipeline to only include controller resources in proper order now.

I have no errors, but the User variable is not available either in the page or in console

Maybe this screenshot is helpful to explain. http://i.imgur.com/Fy1ga.png

dnagir commented 12 years ago

You need to export the classes into the global namespace as CoffeeScript wraps it in a closure.

You may want to write:

class @User extends ko.Model
 # instead of
class User extends ko.Model

This is not related to this gem at all, neither it is related to assets pipeline.

amalagaura commented 12 years ago

I can edit your readme to mention this and the previous stumbling block. I am quite a novice in dealing with javascript

dnagir commented 12 years ago

I am not sure that I want to explain in the README how to use CoffeeScript/JavaScript. But if you think it is extremely confusing, then feel free to send a pull request. I'll consider it.

amalagaura commented 12 years ago

I am trying to understand why in your example you have the class Page instead of

if that code is put in a page.js and loaded with the page, the Page class is not available later in your example to create an instance variable of Page.

dnagir commented 12 years ago

Because @Page is similar to this.Page = which translates into window.Page =. If you don't use @, then the Page is not exported and not available.

If you don't understand that, then it is similar to:

class Page extends ko.Model
  @configure "page"

this.Page = Page # export into the global namespace

The sample in README assumes that the code and definition are in the same file where there is no "export" issue as everything is available.

You really need to learn the CoffeeScript/JavaScript if you still don't understand it by now.

amalagaura commented 12 years ago

I did 'compile' the coffeescript to see the difference in the examples you gave me, so i understood after that. I assumed in your README that they were in separate files, with the coffeescript being in something similar to a page.coffee and then the inline javascript in the view. So I thought the example was organized like that.

dnagir commented 12 years ago

Well, I'm not sure what the exact issue then. Is this 36fe41464c362bdf9678287f959a3a2cf22b2616 what you are after?

amalagaura commented 12 years ago

Yeah ;-) Hopefully then noobs like me won't have to create issues ;-)