javascript in html file

16 views
Skip to first unread message

Johnny Stewart

unread,
Jul 1, 2016, 3:20:42 PM7/1/16
to rubyonra...@googlegroups.com
Hi,

I have 2 views on which I am running some javascript for a rating:

from first view:

<script>
$(document).on('turbolinks:load', function() {
$('.star-rating').raty({
path: '/assets/',
readOnly: true,
score: function() {
return $(this).attr('data-score');
}
});
});
</script>

and second:

<script>
$(document).on('turbolinks:load', function() {
$('#star-rating').raty({
path: '/assets/',
scoreName: 'review[rating]'
});
});
</script>

now here they work fine as is but, I don't want them in the html so I
have moved them into reviews.coffee

however, now on using browser forward and back buttons more stars are
added every time I move back and forward with the browser(this doesn't
happen if I leave them in the views)

I can't work out how to fix this (I also have the feeling I shouldn't be
using turbolinks:load like this)

If anyone with decent javascript knowledge could point me in the right
direction I'd be grateful..

thanks,

J.

--
Posted via http://www.ruby-forum.com/.

Walter Lee Davis

unread,
Jul 1, 2016, 4:53:49 PM7/1/16
to rubyonra...@googlegroups.com
You may want to modify the raty() method so that it will only initialize the object it is called on once. Set a semaphore on that object, and if it is present, fall through.

Walter

>
> I can't work out how to fix this (I also have the feeling I shouldn't be
> using turbolinks:load like this)
>
> If anyone with decent javascript knowledge could point me in the right
> direction I'd be grateful..
>
> thanks,
>
> J.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b7192a2c48791e5f8bee26b1e763742c%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages