Skip to content

Instantly share code, notes, and snippets.

@spalladino
Created May 23, 2012 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spalladino/2774757 to your computer and use it in GitHub Desktop.
Save spalladino/2774757 to your computer and use it in GitHub Desktop.
Organizing coffeescript code in a Rails 3 app
if $('#my_div_in_complex_page').length > 0
class Foo
...
# on a global functions file
@onComplexFunctionality = (callback) -> $(-> callback() if $('#my_div_in_complex_page').length > 0)
# when you need to use it
onComplexFunctionality >
class Foo
...
Site.users.index = () ->
# your code for users/index here...
<body data-controller="<%= controller_name %>" data-action="<%= action_name %>">
class window.Foo
# your code for the class...
class @Foo
# your code for the class...
# in file A.js.coffee
class @A extends B
# fails because B has not been defined yet
# in file B.js.coffee
class @B
# is defined after A as this file is processed after A.js.coffee
# in file A.js.coffee
#= require B
class @A extends B
...
# in file B.js.coffee
class @B
...
@elgalu
Copy link

elgalu commented Aug 21, 2013

I think you have a missing hyphen "-" at blog02.js.coffee line 5
https://gist.github.com/spalladino/2774757#file-blog02-js-coffee-L5

onComplexFunctionality >
# Should be
onComplexFunctionality ->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment