Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

losing rating capability after ajax load #8

Closed
uorji3 opened this issue Nov 15, 2012 · 4 comments
Closed

losing rating capability after ajax load #8

uorji3 opened this issue Nov 15, 2012 · 4 comments

Comments

@uorji3
Copy link

uorji3 commented Nov 15, 2012

Let me first start by saying "Great gem".

On my page, I use your star rating but the user can click on a link to update a div element using ajax.
After the ajax load, all of the javascript for the star rating breaks.

I've been using the jquery "on" event for other javascript functions that I have created but I don't know how to use to fix the star rating.

How can I reload letsrate.js.erb and jquery.raty.js after an ajax load?

@igorlebovic
Copy link

Having the same issue. Any guidance would be highly appreciated.

@uorji3
Copy link
Author

uorji3 commented Nov 28, 2012

Igor,
I decided to scrap the 5 star rating and go with a simple like/dislike rating.
I'm using the act-as-votable gem.
It's a simpler design but all of my Jquery stays in tact.

@Balaraju
Copy link

Balaraju commented Mar 6, 2013

Having The Same issue

@victorcreed
Copy link

I resolved this problem like this

$.fn.raty.defaults.path = "/assets";
$.fn.raty.defaults.half_show = true;
window.applyRaty = function(){
$(".star").raty({
score: function(){
return $(this).attr('data-rating')
},
number: function() {
return $(this).attr('data-star-count')
},
click: function(score, evt) {
$.post('<%= Rails.application.class.routes.url_helpers.rate_path %>',
{
score: score,
dimension: $(this).attr('data-dimension'),
id: $(this).attr('data-id'),
klass: $(this).attr('data-classname')
},
function(data) {
if(data) {
// success code goes here ...
}
});
}
});
}
$(function(){
applyRaty();
});

then call applyRaty() in *.js.erb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants