javascript - uninitialized constant Object::Element in Opal RB -


trying hand @ opal/jquery. app.rb file looks this:

require 'opal' require 'opal-jquery'  class htmlobject   def initialize    end    def write_to_body    end end   class htmlparagraph < htmlobject   attr_accessor :inner_html   def initialize(text)     @inner_html= text   end    def write_to_body      @body = element.find("#body")     @body.append(element("<p>#{@inner_html}"))   end end  p = htmlparagraph.new("hello world") p.write_to_body 

i compile using example site app.js. run in web browser index.html:

<!doctype html> <html> <head>     <script src="jquery-1.10.1.min.js" type="text/javascript"></script>     <script src="opal.js" type="text/javascript"></script>     <script src="opal-jquery.min.js" type="text/javascript"></script>     <script src="opal-parser.js" type="text/javascript"></script>     <script src="app.js" type="text/javascript"></script>     <title></title> </head> <body>  </body> </html> 

when open page not see anything. console reveals error trace:

uncaught nameerror: uninitialized constant object::element opal.js:1531 def.$backtrace.backtrace opal.js:1531 def.$raise opal.js:1279 def.$const_missing opal.js:575 opal.cm opal.js:255 def.$write_to_body app.js:44 (anonymous function) app.js:51 (anonymous function) 

the js output file reads thus:

 function(__opal) {   var p = nil, _a, _b, self = __opal.top, __scope = __opal, nil = __opal.nil, $mm = __opal.mm, __breaker = __opal.breaker, __slice = __opal.slice, __klass = __opal.klass;   (function(__base, __super){     function htmlobject() {};     htmlobject = __klass(__base, __super, "htmlobject", htmlobject);      var def = htmlobject.prototype, __scope = htmlobject._scope;      def.$initialize = function() {        return nil;     };      def.$write_to_body = function() {        return nil;     };      return nil;   })(self, null);   (function(__base, __super){     function htmlparagraph() {};     htmlparagraph = __klass(__base, __super, "htmlparagraph", htmlparagraph);      var def = htmlparagraph.prototype, __scope = htmlparagraph._scope;     def.inner_html = def.body = nil;      def.$inner_html = function() {        return this.inner_html     },      def['$inner_html='] = function(val) {        return this.inner_html = val     }, nil;      def.$initialize = function(text) {        return this.inner_html = text;     };      def.$write_to_body = function() {       var _a, _b, _c;       this.body = ((_a = ((_b = __scope.element) == null ? __opal.cm("element") : _b)).$find || $mm('find')).call(_a, "#body");       return ((_b = this.body).$append || $mm('append')).call(_b, ((_c = this).$element || $mm('element')).call(_c, "<p>" + (this.inner_html)));     };      return nil;   })(self, ((_a = __scope.htmlobject) == null ? __opal.cm("htmlobject") : _a));   p = ((_a = ((_b = __scope.htmlparagraph) == null ? __opal.cm("htmlparagraph") : _b)).$new || $mm('new')).call(_a, "hello world");   return ((_b = p).$write_to_body || $mm('write_to_body')).call(_b); })(opal); 

any ideas?

try putting opal , opal-jquery directly inside html, , leaving requires out of app.rb, can grab them http://cdnjs.com.

otherwise i'd see compiled app.js (you can put in gist).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -