Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6219077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:43:04+00:00 2026-05-24T07:43:04+00:00

Working with Rails 3.1 (rc5), and I’m noticing that any coffeescript file I include

  • 0

Working with Rails 3.1 (rc5), and I’m noticing that any coffeescript file I include rails (or sprockets) is adding in initializing javascript at the top and bottom. In other words, a blank .js.coffee file gets outputted looking like this:

(function() {
}).call(this);

This is irritating because it screws up my javascript scope (unless I really don’t know what I’m doing). I generally separate all of my javascript classes into separate files and I believe that having that function code wrapping my classes just puts them out of scope from one another. Or, atleast, I can’t seem to access them as I am continually getting undefined errors.

Is there a way to override this? It seems like this file in sprockets has to do with adding this code:
https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/jst_processor.rb

I understand that wrapping everything in a function might seem like an added convenience as then nothing is ran until DOM is loaded, but as far as I can tell it just messes up my scope.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:43:05+00:00Added an answer on May 24, 2026 at 7:43 am

    Are you intending to put your objects into the global scope? I think CoffeeScript usually wraps code in anonymous functions so that it doesn’t accidentally leak variables into the global scope. If there’s not a way to turn it off, your best bet would probably be to specifically add anything you want to be in the global scope to the window object:

    window.myGlobal = myGlobal;
    

    It seems to be a javascript best practice these days to put code inside a function scope and be explicit about adding objects to the global scope, and it’s something I usually see CoffeeScript do automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im using rails 3.1.4.rc5 and my javascript doesnt seem to be working. in my
I'm working on a Rails app and am looking to include some functionality from
I am working on a Rails application that needs to handle dates and times
I'm working on a rails app that has a whole bunch of before filters
I'm working on a Rails app that sends data through a form. I want
I'm working on a Rails app that existing users can invite additional members to
I have a library that I'm trying to get working with rails 3 (specifically
I have a working rails 3.1 application that uses the mercury wysiwyg editor, however
Working with Rails 3.0, if one wanted to render some partial through javascript (in
I read sometimes from people that seem to be working with rails since longer,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.