I've been developing a Ruby on Rails Application featuring a Rating System. The rating system is functioning as expected, and I have successfully implemented ajax functionality. Additionally, I am now looking to display the current average rating in a bar graph where the length of the bar corresponds to the average value of all ratings.
The calculation for setting the bar's length is as follows:
var average = parseFloat( $(".rating_filled").attr("data-average") );
var avg_width = (average/5)*200;
$(".rating_filled").css("width", avg_width);
The data value is provided in the HTML code like this:
<div class="rating_bar">
<div class="rating_filled" data-average="<%<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="665b2601070b03481407120f0801154807100314070103">[email protected]</a>(:value) %>"></div>
</div>
When I use ajax to reload the partial containing the bar graph and other statistics after submitting a rating, everything refreshes except for the bar graph itself. The Firebug tool indicates that the bar receives the updated value from the recent submission, but the graphical representation disappears completely.
It seems like the issue lies in the fact that the JavaScript file responsible for defining the graphical length does not reload via ajax, resulting in the bar not being displayed at all. I'm unsure if I need to update my jQuery commands or make adjustments in my controller to pass the data through Json.
If anyone has insights or suggestions on how to resolve this issue, I would greatly appreciate it!