coffeescript

Call javascript function onclick in Rails

自闭症网瘾萝莉.ら 提交于 2019-12-21 02:45:11
问题 I have the following code in one of my views: <button type="button" onclick="analyze();">Analyze</button> And, the .js.coffee file for the corresponding controller contains analyze = -> $.ajax type: "GET" url: "http://localhost:3000/api/logs" success: (data) -> Analytics.doAnalysis data return; return; But, when I click the button, I get an error in console saying Uncaught ReferenceError: analyze is not defined . I think my onclick is not correctly defined. What is the recommended way of

How to enable harmony syntax support in coffeescript?

妖精的绣舞 提交于 2019-12-21 02:27:08
问题 I used node.js(0.11.13) with --harmony flag and used function *() and yield keywords. I tried to simplify my development on node.js with help of coffeescript, so far it works great but I went into troubles with yield and declaring a generator - it complains about 'reserved keyword yield' . Any ideas? 回答1: Another way to open the gate to the black dimension is: co = require 'co' sleep = require 'co-sleep' co(`function*(){1` console.log 'hi!' `yield sleep(1000)` console.log 'bye!' `1}`)() It's

Future of the with-statement in Javascript

自闭症网瘾萝莉.ら 提交于 2019-12-21 01:16:14
问题 I know that usage of the with -statement is not recommended in Javascript and is forbidden in ECMAScript 5, but it allows one to create some nice DSLs in Javascript. For example CoffeeKup-templating engine and the Zappa web DSL. Those uses some very weird scoping methods with the with -statement to achieve DSLish feeling to them. Is there any future with the with -statement and these kinds of DSLs? Can this DSL-effect be achieved without the with -statement? 回答1: with being "forbidden" in

Partials in Coffee HAML (.hamlc)

放肆的年华 提交于 2019-12-20 18:34:36
问题 I am using backbone.js on a rails backend with HAML Coffee , which is compiled by haml_coffee_assets. There is some duplication in my templates. Is there a way to create rails-like partials to dry up my templates? Addition: Can I do content_for(:something) in Coffee HAML? 回答1: There is no content_for helper in Haml Coffee, but you simply can render another template within a template. Without Local Variables For example, you've a template test : %p My Partial %ul %li Is included You can

CoffeeScript editor plugin for Eclipse?

拈花ヽ惹草 提交于 2019-12-20 17:25:19
问题 Here's the deal, I use Wro4j to handle the transpilation/'building' of .coffee files to .js ones. Now I want to have a good editor plugin which supports CoffeeScript, and I don't want to install Aptana (I only need CoffeeScript, not Python, Ruby and all the other stuff it includes and doesn't let me choose not to install...). Many thanks! 回答1: Have you tried coffeescript-eclipse plugin? https://github.com/adamschmideg/coffeescript-eclipse 回答2: Besides CoffeScript-Eclipse: https://github.com

how should I include a coffeescript file on only one page?

帅比萌擦擦* 提交于 2019-12-20 11:11:36
问题 Edit: a year later if I was going to do this again I'd do it with curl.js instead of Rails asset pipeline. Related: Best way to add page specific javascript in a Rails 3 app? I'm writing an app and using coffeescript to generate all of the js. That's why the related question doesn't do what I need. I'd like to be able to put a coffeescript file in a subfolder of my assets directory and have that .coffee file only get served up on one page. The page is on a named route match 'myNotifications'

What is the easiest way to test for class membership in coffeescript?

梦想与她 提交于 2019-12-20 09:55:15
问题 I'm looking for an equivalent of Ruby's "blah".is_a?(String) of Objective-C's [@"blah" isKindOfClass:[NSString class]] 回答1: Do you want to test whether an object is descended from a particular class? Then you want the instanceof keyword. (It's not something added by CoffeeScript; it's a part of JavaScript.) CoffeeScript classes are set up so that if you write class A class B extends A class C extends B then the following is true: (new A) instanceof A (new B) instanceof B and (new B)

Node.js user authentication using passport

故事扮演 提交于 2019-12-20 09:45:04
问题 (updated code with serialization functions - still redirects to /failedRedirect) I'm trying to get simple username/password authentication going using the passport package, but failing. In the example below I've tried to verify that authentication works by basically always returning a valid authentication (regardless of what gets passed), but for some reason it fails and passport redirects to the failed login link. If anybody could help me out in figuring out how to get this example to simply

Backbone and Rails associations: Avoiding JSON HashWithIndifferentAccess errors

时光怂恿深爱的人放手 提交于 2019-12-20 09:39:11
问题 I'm trying to get my backbone associations working inside a rails app , and I'm having difficulty when trying to update existing models. Specifically, Rails throws the following error: Started PUT "/posts/2" for 127.0.0.1 at 2012-01-04 02:36:14 +1000 Processing by PostsController#update as JSON Parameters: {"post"=>{"content"=>"Seconderona", "created_at"=>"2012-01-03T10:51:09Z", "id"=>2, "title"=>"Second test post", "updated_at"=>"2012-01-03T10:51:09Z", "comments"=>[{}]}, "id"=>"2"} Post Load

Confused with all the Node JS frameworks/libraries etc. around [closed]

霸气de小男生 提交于 2019-12-20 09:37:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm feeling a bit confused, there are so many frameworks out there for Node.js related 'stuff'. Would someone be able to give me an overview of - how the following libraries/frameworks/whatever relate/interact with each other - what's included or what the main purpose is for each of them? - differences between