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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:27:37+00:00 2026-06-16T20:27:37+00:00

Just getting to the CoffeeScript part of my first rails app; never did any

  • 0

Just getting to the CoffeeScript part of my first rails app; never did any JS/CoffeeScript before, so lots of questions. Starting with:

In my app, users can “claim” (take ownership of) tasks (or ideas, as I call them). Each user may have up to 3 ideas at any given time. So:

1) My current code looks like this:

$ ->
  exports = this
  exports.claimedCount = 0
  $('.claim').bind 'ajax:success', ->
    $(this).text("Claimed")
    $(this).addClass("btn-success")
    claimedCount++
    alert(claimedCount)

What this is supposed to do is declare a global var claimedCount and increment it every time the user claims an idea. What is actually does is nothing: Uncaught ReferenceError: claimedCount is not defined

Why is that? How should I really define the variable? Do I even need a global variable for what I’m trying to do? (Each idea has its own Claim button).

2) The user might render the page when they already have a few ideas claimed. Thus, I need to set the claimedCount using Rails when first rendering the page. Any pointers on this would be greatly appreciated (should I rename my .js.coffee file to .js.coffee.erb and do it there? What’s the usual spot for js init code like this?)

Many thanks for any help you can give.

  • 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-16T20:27:39+00:00Added an answer on June 16, 2026 at 8:27 pm

    I agree with Khaled’s answer on the first question.

    On the second one, I would rather rename the file to .js.coffee.erb so that it is preprocessed with erb first and write something like :

    window.claimedCount = <%= @user.claims.count %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just getting my head around Linq and having lots of fun! Can any one
Just getting started building an app using the v6 of the facebook c# sdk
I'm just getting started with Boost for the first time, details: I'm using Visual
Using CoffeeScript in a Rails 3 app I have a simple ajax call: $(document).ready
Just getting started with iphone and ipad apps. Lots of reading, lots of tinkering,
Just getting started with MSpec and I can't seem to quite get my first
Just getting started with Coffeescript and have installed it correctly , however having problems
Working with Rails 3.1 (rc5), and I'm noticing that any coffeescript file I include
I was writing some CoffeeScript just now, and getting a strange error: TypeError: Thing(param)
Just getting started using MVC in ASP.NET, I'm going to have it so users

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.