coffeescript

Get a Backbone Model instance's model/class name

五迷三道 提交于 2019-12-22 01:12:53
问题 Given an instance of Backbone model, how can I know the "class" (so to speak) of this instance ? For instance: class Car extends Backbone.Model mycar = new Car() And what I need is: mycar.modelName # => 'Car' 回答1: It's problematic in general, I think. I was going to suggest some of the options mentioned here ( How do I get the name of an object's type in JavaScript? ) but I was having issues with the first option. You could always extend all your models to have a function that returned a

Change attribute using checkbox, AJAX, jQuery

谁都会走 提交于 2019-12-22 00:28:25
问题 I wish to change the boolean attribute of my Task resource depending on wether checkbox is checked or not. I am stuck as I don't know what to do... I have everything before adding this AJAX checkbox working, whole CRUD, everything tested with rspec and capybara and bootstrapped. I have the following code... views/tasks/show.html.erb 27 <%= form_for [@project, @task], :remote => true do |f| %> 28 <%= f.label :completed %> 29 <%= f.check_box :completed %> 30 <% end %> This :completed is the

Dojo + Rails 3.2.8 + CoffeeScript

只谈情不闲聊 提交于 2019-12-21 21:11:22
问题 I'm trying to use Dojo Toolkit 1.8 instead JQuery in a Rails 3.2.8 web application, mainly due of the lack of a complete and visually uniform widget based on JQuery. Followed these steps: Unzip dojo, dijit and dojox directories into app/assets/javascripts Changed in application.js //= require_tree . to //= require_directory . Edited application layout (Not unobtrusive yet... just to effect of testing) views/layouts/application.html.erb <!DOCTYPE html> <html> <head> <title>Dojo</title> <%=

Rails 3.1 Ajax question

隐身守侯 提交于 2019-12-21 20:49:33
问题 I have a scaffold called post which has a title and a description. On my layout I have a link to create a new post that has :remote => true. How would I make it when I click on that remote link to change the content of a div so that I can create a new post? 回答1: Let's suppose the action you will use is called new . You should create a file called new.js.erb into views/posts that will be rendered when you post remotely your form. That file must include the javascript that places the new post

Fixing Initializers deprecation in Ember 1.12.0

时光毁灭记忆、已成空白 提交于 2019-12-21 12:30:22
问题 I am refering to this particular deprecation that was introduced in Ember 1.12 lookup was called on a Registry. The initializer API no longer receives a container, and you should use an instanceInitializer to look up objects from the container I looked at the guide, but I am unsure on how to fix this. Here's a snippet of the code I have at the moment initialize = (container, app) -> auth = container.lookup('auth-manager:main') local_config = ($.ajax type: 'GET' url: '/config.json' async:false

How to create a CoffeeScript style existential operator in JavaScript?

随声附和 提交于 2019-12-21 09:05:20
问题 CoffeeScript turns user?.id into if (typeof user !== "undefined" && user !== null) { user.id; } Is it possible to create a JavaScript function exists that would do something similar? i.e. exists(user).id would result in either user.id or null It would be easier if a function accepts another parameter, i.e. exists(user, 'id') , but that wouldn't look as nice. 回答1: No, you can't produce such a function. The problem is that this: any_function(undeclared_variable) will produce a ReferenceError if

how to pass compiler options to mocha

江枫思渺然 提交于 2019-12-21 07:28:39
问题 I run a mocha command to run my tests $ ./node_modules/.bin/mocha --compilers coffee:coffee-script -R spec I wish to pass additional options to the coffee-script compiler (--bare to avoid the outer closure that is introduced when compiling .coffee to .js). Is there a way to do this? I tried $ ./node_modules/.bin/mocha --compilers coffee:coffee-script --bare -R spec but that doesn't look right. It also failed saying that --bare is not a valid option for mocha. error: unknown option `--bare'

Convert image data to render an image in the browser

人盡茶涼 提交于 2019-12-21 05:36:04
问题 I am trying to download an encrypted image file from Amazon S3 through a presigned_link with AJAX, and is getting a bunch of image data gibberish. $(document).on 'click', '.js-download', (event) -> event.preventDefault() $.ajax type: "GET" url: event.currentTarget.href contentType: 'image/jpeg', headers: { 'x-amz-server-side-encryption-customer-algorithm': 'AES256', 'x-amz-server-side-encryption-customer-key': customer_key, 'x-amz-server-side-encryption-customer-key-MD5': customer_key_md5, }

rails, getting syntax error with coffee script

北城余情 提交于 2019-12-21 04:16:21
问题 i am trying to do an autocomplete feature in rails using the jquery ui library. however i keep getting syntax errors "Syntax Error: reserved word "function" on line ..." this is my lessons.js.coffee file jQuery -> $(function() { function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } $( "#lesson_tag_name" ) // don't navigate away from the field on tab when selecting an item .bind( "keydown", function( event ) { if ( event.keyCode ===

Brunch how to disable RequireJS module wrapping

夙愿已清 提交于 2019-12-21 03:53:07
问题 Update: For anyone interested in using Brunch with AngularJS I've put together a seed project angular-brunch-seed I'm using Brunch with AngularJS. AngularJS provides a module system so the need for importing file using commonJS / AMD is redundant. Is it possible to disable this feature for files in the /app directory? Essentially I would like it to compile files unaltered like it does for the /vendor directory. So the preferred out come would be: joinTo: 'js/app.js': /^app/ 'js/vendor.js': /