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 8234693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:34:11+00:00 2026-06-07T18:34:11+00:00

In my Rails app I have some plain old JS: function reorder(divid,url) { jQuery(divid).sortable({

  • 0

In my Rails app I have some plain old JS:

    function reorder(divid,url) {
        jQuery(divid).sortable({
          axis: 'y',
          dropOnEmpty: false,
          handle: '.drag',
          cursor: 'crosshair',
          items: 'li',
          opacity: 0.4,
          scroll: true,
          update: function(){
            jQuery.ajax({
              type: 'post',
              data: jQuery(divid).sortable('serialize'),
              dataType: 'script',
              url: url)
          }
        });
    }

and it works when I call:

     reorder("#pages","<%= changeorder_pages_path %>");

So I decided to convert my function to CoffeeScript which gave me this:

(function() {
  var reorder;

  reorder = function(divid, url) {
    return jQuery("#pages").sortable({
      axis: "y",
      dropOnEmpty: false,
      handle: ".drag",
      cursor: "crosshair",
      items: "li",
      opacity: 0.4,
      scroll: true,
      update: function() {
        return jQuery.ajax({
          type: "post",
          data: jQuery("#pages").sortable("serialize"),
          dataType: "script",
          complete: function(request) {
            return jQuery("#pGESs").effect("highlight");
          },
          url: "/pages/changeorder"
        });
      }
    });
  };

}).call(this);

but my call doesn’t work any more – I get the Firebug error:

reorder is not defined

So to my question – how do I call the function now it is CoffeeScripted?

I have read this: Calling a function by its name

But I have no idea what they are talking about. I have never used global=this and have no idea what it does or why I would want to use it.

I read this as well: http://elegantcode.com/2011/06/30/exploring-coffeescript-part-2-variables-and-functions/

As well as this: http://www.informit.com/articles/article.aspx?p=1834699

I realise that CoffeeScript is protecting me from global variables and making my code better – but I can’t find an explanation as how to call functions.

I have played with the CoffeeScript web site and played with the cube function – so I should just be able to call the function name I think.

I’m asking the question because I have a gap in my knowledge – any help filling that gap will be much appreciated.

  • 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-06-07T18:34:13+00:00Added an answer on June 7, 2026 at 6:34 pm

    CoffeeScript doesn’t create globals by default, and it seems as if you are trying to access a reorder outside the file it was defined in.

    However you can explicitly put something in the global namespace by writing

    window.reorder = reorder
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem with creating a function to my Rails app. I want
I have some simple jQuery that renders a page in my Rails app. Here's
In a Ruby on Rails app, we have some details which are stored as
I have setup some simple associations in my rails app: resources :properties do resources
I have already implemented some AJAX pagination in my Rails app by using the
I have a rails app with some nested data that I'd like to export
I have got Sinatra/Rails app and an action which starts some long process. Ordinary
I have a MySQL/Rails app that needs search. Here's some info about the data:
I'm trying to make logging for my rails app and have some dilemmas over
Some of the users of our Ruby on Rails app have complained that page

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.