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

  • Home
  • SEARCH
  • 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 886931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:08:59+00:00 2026-05-15T13:08:59+00:00

Excuse my daftness, but I can not understand how ruby vars can be attained

  • 0

Excuse my daftness, but I can not understand how ruby vars can be attained with jQuery. I made a button that by json POSTS to the server to make a credit_status = 0. But I would like that 0 to also auto-update on the page as well.

My View:

HQ $
= organization.total_credit
= link_to 'redeem', redeem_admin_organization_path(organization), :class => 'button_short redeem live'

redeem.js :

== $("#organization_#{@organization.id} .redeem").html("#{escape_javascript(link_to('redeem', redeem_admin_organization_path(@organization), :class => 'button_short live redeem'))}");

controller ( not sure if you need to see this ):

def redeem
  @organization = Organization.find(params[:id])
  users_who_promoted = CardSignup.find(:all).select {|c| c.store_id == @organization.id && c.credit_status == true}
  unless users_who_promoted.empty?
    users_who_promoted.update_all("credit_status","false")
  end
  @organization.update_attribute('total_credit', '0')
end

main.js:

$(".live").live("click", function() {
    $.ajax({type: "GET", url: $(this).attr("href"), dataType: "script"});
    return false;
});

Does anyone know how to draw and update a single variable on a page using jSon/jQuery/Rails? Is there a really good resource out there for learning this?

  • 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-15T13:09:00+00:00Added an answer on May 15, 2026 at 1:09 pm

    app/controllers/vouchers_controller.rb

    class VouchersController < ApplicationController # Just made up the name
      def redeem
        @organization = Organization.find(params[:organization_id])
        @organization.update_attribute('total_credit', 0)
        respond_to do |format|
          format.js
        end
      end
    end
    

    app/views/vouchers/redeem.js.erb

    $("#organization_<%= @organization.id %> .redeem").html(
      "<%= escape_javascript(link_to('redeem', 
                                     redeem_admin_organization_path(@organization), 
                                     :class => 'button_short live redeem')) %>");
    
    $(".total_credit").text( "<%= @organization.total_credit %>" );
    

    The important thing to understand is that redeem.js.erb is just another erb-template with the same syntax as in *.html.erb

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

Sidebar

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.