1

So ive got ratyrate working in development just fine by adding

<%= javascript_include_tag 'ratyrate.js', "data-turbolinks-track" => false %>

to the body of my view. Prior to this the stars would only load when the url was directly accessed or the page refreshed.

Now I am having the exact same issue (stars not loading when page is accessed through a link) when deploying my app on heroku!

I hope that this is enough info (happy to provide more) and that someone has faced this before/has any ideas! Thanks!

solved - see answer

DanaeB
  • 85
  • 8

3 Answers3

5

So the problem was that I forgot to run rake assets:precompile. The solution for development mentioned in the question should work.

SOLUTION

Add <%= javascript_include_tag 'ratyrate.js', "data-turbolinks-track" => false %> to the head (seems to run faster) or body tag in your view.

Also add Rails.application.config.assets.precompile += %w( ratyrate.js ) to config/initializers/assets.rb.

Then make sure you run rake assets:precompile to avoid looking as silly as me!

Hope this helps someone :)

DanaeB
  • 85
  • 8
2

My way to fix it:

jquery.raty.js

rename jquery.raty.js to jquery.raty.js.erb and replace images options with asset_path, for example:

cancelOff : 'cancel-off.png'

will become

cancelOff    : '<%= asset_path('cancel-off.png') %>'

raty_helper.rb

I have moved rating_for method from raty helper to one of my helpers files, I had to override some things anyway, like do not allow user to rate himself that didn't worked out of the box.

Changes I did in this file:

star_path    = options[:star_path]    || ''
star_on      = options[:star_on]      || image_path('star-on.png')
star_off     = options[:star_off]     || image_path('star-off.png')
star_half    = options[:star_half]    || image_path('star-half.png')
cancel_on    = options[:cancel_on]    || image_path('cancel-on.png')
cancel_off   = options[:cancel_off]   || image_path('cancel-off.png')

basically I removed the / before each image name, it was for example:

star_on      = options[:star_on]      || image_path('/star-on.png')

now I can push to heroku and it works as expected without having to run assets precompile on my local machine and push it all to heroku.

rmagnum2002
  • 11,341
  • 8
  • 49
  • 86
0

This is happening because image locations aren't referencing the asset pipeline. I had to create a new helper file to override the rating_for methods to pull in images from the asset pipeline.

  1. Create a new helper file (raty_helper.rb) in config/initializers
  2. Add "module RatyHelper" to as line 1 of new file
  3. Copy line 2 through line 144 from https://github.com/wazery/ratyrate/blob/master/lib/ratyrate/helpers.rb into your new helper.