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?