coffeescript

Ajax call in rails 3.2.3 with will_paginate gem

时间秒杀一切 提交于 2019-12-17 19:26:42
问题 Im trying to implement an Ajax call with the will_paginate gem, I found this guide http://ramblinglabs.com/blog/2011/11/rails-3-1-will_paginate-and-ajax which seemed like a simple solution, though it includes coffeescript which i am not familiar with, so if anyone has a different solution then please advise.. My code is as follows My View <div class="container"> <div class="row"> <div id="userRecipes"> <%= render partial: 'userrecipes' %> </div> </div><!--/row--> My partial (userrecipes) <%

Exclude route from express middleware

混江龙づ霸主 提交于 2019-12-17 18:28:27
问题 I have a node app sitting like a firewall/dispatcher in front of other micro services and it uses a middleware chain like below: ... app.use app_lookup app.use timestamp_validator app.use request_body app.use checksum_validator app.use rateLimiter app.use whitelist app.use proxy ... However for a particular GET route I want to skip all of them except rateLimiter and proxy. Is their a way to set a filter like a Rails before_filter using :except/:only? 回答1: Even though there is no build-in

Structuring coffeescript code?

限于喜欢 提交于 2019-12-17 18:25:49
问题 Under Rails 3.1, I'm trying to find out how to move a few coffeescript classes away from my controller default coffeescript file ( home.js.coffee ) into another file, in order to structure the whole a little bit. Does anyone know how to "include" a coffeescript file into another? 回答1: What you want to do is export functionality. For instance, if you start with class Foo ... class Bar extends Foo ... and you decide you move Foo to its own file, that file should look like class Foo ... window

How do I associate a CoffeeScript file with a view?

帅比萌擦擦* 提交于 2019-12-17 18:18:50
问题 Just installed rails 3.1 rc1 and am trying to grok the best way to manage javascript with the new asset pipeline By default all coffeescript is compiled into a single application.js file, this is a good thing. Each seperate coffee script file is appended to the js file and wrapped in an anonymous function which is executed via the call method A common scenario would be to use some jquery to turn various forms into ajax forms, update UI, etc... Many of these scripts will be specific to a

Multiple Files communication with coffeescript

回眸只為那壹抹淺笑 提交于 2019-12-17 17:39:12
问题 When I create a new coffeescript file, I cannot access the code in the compiled code from another file because it gets wrapped in some function scope. For example: CoffeeScript: class ChatService constructor: (@io) -> Generated Javascript: (function() { var ChatService; ChatService = (function() { function ChatService(io) { this.io = io; } return ChatService; })(); }).call(this); When trying to call ChatService in another file, it's not defined. How do I handle multiple files with

A Backbone.js Collection of multiple Model subclasses

只愿长相守 提交于 2019-12-17 17:28:43
问题 I have a REST Json API that returns a list "logbooks". There are many types of logbooks that implement different but similar behavior. The server side implementation of this on the Database layer is a sort of Single Table Inheritance, so each JSON representation of a logbook contains its "type" : [ {"type": "ULM", "name": "My uml logbook", ... , specific_uml_logbook_attr: ...}, {"type": "Plane", "name": "My plane logbook", ... , specific_plane_logbook_attr: ...} ] I would like to replicate

Chrome doesn't recognize console.log when it's called log

扶醉桌前 提交于 2019-12-17 16:49:18
问题 Like all programmers, I'm lazy. So in my utils.js there's a simple line: window.log = console.log This works fine in firefox , but it makes Chrome cry like a little boy. I have to write console.log to make it work. Any suggestions? 回答1: Chrome's console.log apparently pays attention to what this is so if you do this: window.log = console.log log('pancakes') Then you'll get nothing more than a "TypeError: Illegal invocation" exception for your efforts. However, if you force the appropriate

How to use mongoose findOne

时光总嘲笑我的痴心妄想 提交于 2019-12-17 16:03:37
问题 I have the below schema (apologies that it is in coffeescript) Schema = mongoose.Schema AuthS = new Schema auth: {type: String, unique: true} nick: String time: Date Auth = mongoose.model 'Auth', AuthS I simply want to recover one record which is definitely in my database: Auth.findOne({nick: 'noname'}, function(obj) { console.log(obj); }); Unfortunately this always logs null . db.auths.findOne({nick: 'noname'}) in mongo shell always returns a value. What is going on? 回答1: Found the problem,

How to use mongoose findOne

烈酒焚心 提交于 2019-12-17 16:02:50
问题 I have the below schema (apologies that it is in coffeescript) Schema = mongoose.Schema AuthS = new Schema auth: {type: String, unique: true} nick: String time: Date Auth = mongoose.model 'Auth', AuthS I simply want to recover one record which is definitely in my database: Auth.findOne({nick: 'noname'}, function(obj) { console.log(obj); }); Unfortunately this always logs null . db.auths.findOne({nick: 'noname'}) in mongo shell always returns a value. What is going on? 回答1: Found the problem,

Grunt: Watch multiple files, Compile only Changed

馋奶兔 提交于 2019-12-17 15:42:56
问题 I'm new to Grunt, and so far I'm enjoying it very much. I want Grunt to compile only the changed files when running grunt watch In my Grunfile.coffee I currently have (relevant parts). Note: assets/javascript/app.coffee and assets/javascript/app.js are directories coffee: default: expand: true cwd: "assets/javascript/app.coffee" src: ["*.coffee"] dest: "assets/javascript/app.js" ext: ".js" uglify: dev: options: beautify: true compress: false mangle: false preserveComments: 'all' files: "js