wazery / ratyrate

:star: A Ruby Gem that wraps the functionality of jQuery Raty library, and provides optional IMDB style rating.
http://ratingmoviestore.herokuapp.com
237 stars 120 forks source link

Stars not displayed in production (Heroku) #42

Open maxvlc opened 10 years ago

maxvlc commented 10 years ago

Hi...

I'm deploying my app on Heroku and I've a problem with star images.

The app in development it's working OK.

It seems that the problem in production resides in the way that the images are accessed. You can't access to the image name directly because they're precomplied rake adds a hash between the name and the extension.

Any suggestion?

Thanks...

wazery commented 10 years ago

I will invistigate this issue and report back to you.

Thanks for your report

On Wednesday, August 13, 2014, Maximo Carrion notifications@github.com wrote:

Hi...

I'm deploying my app on Heroku and I've a problem with star images.

The app in development it's working OK.

It seems that the problem in production resides in the way that the images are accessed. You can't access to the image name directly because they're precomplied rake adds a hash between the name and the extension.

Any suggestion?

Thanks...

— Reply to this email directly or view it on GitHub https://github.com/wazery/ratyrate/issues/42.

_Islam Wazery_ _Official Member, Ubuntu Twitter: @wazery | Facebook: islamwazery G+: link https://plus.google.com/u/0/114444774108176364727 | Linkedin: in/wazery

oladan commented 9 years ago

any updates?

alexanderad commented 9 years ago

It seems I hit same issue. The thing is that images are requested at this.opt.path + icon, where this.opt.path defaults to /assets/. But on heroku assets are compiled, so that names are actually:

star-half-f547012ca7d997c024966388dfb843cc.png
star-off-700032d6711c66ebe7120e6b51b43503.png
star-on-c68c57c1e01049d961b29fa6e4db9229.png

or similar.

alexanderad commented 9 years ago

I've applied a dirty workaround: renamed jquery.raty.js to jquery.raty.js.erb and added some kind of "assets directory" where each icon is loaded once with <%= asset_path "icon-name" %>

ahnbizcad commented 9 years ago

ohh it's the fingerprinting issue.

What alexanderad said is exactly the solution.

alexanderad commented 9 years ago

I can try to make a PR out of my changes if anyone else is interested.

wazery commented 9 years ago

Yes please issue a PR.

davestephens commented 9 years ago

I've worked out a cleaner way to do this, without having to hack about with jquery.raty.js - you just need to move the images out of the asset pipeline.

Firstly, move the images out of the assets path, and into your /public/images path (I used /public/images/ratyrate), similar to how you would for a favicon.

Then, on the rating_for declaration in your view:

rating_for @model, "dimension_name", star_path: '/images/ratyrate'

...and you're done.

I don't use Heroku, but I did have the same image path issue in production and this fixed it for me. If you want to see this in action, take a look at a recipe on http://www.slowcookerclub.com - notice how the stars are loaded from /images/ratyrate, yet the logo etc come from the asset pipeline.

sunwooz commented 8 years ago

@davestephens Does this workaround still work for heroku? I tried it but rails automatically puts the public folder under gitignore since the changes to the asset pipeline. Is it wise to unignore it?

edit: Ok, it worked for me after unignoring the public folder in .gitignore.

Thanks!

1andee commented 7 years ago

@davestephens This solved part of my problem! You rock!

Elsewhere in our views, we weren't declaring rating_for but instead passing it in as a data attribute: <%=@user.received_ratings.average(:availability).round(2) %>

After moving the images out of the assets path and into /public/images, I simply changed the path in assets/javascripts/ratings.coffee to match:

...
$( '.star-rating' ).raty
    path: '/images/ratyrate',
...

Followed by changing the default path in assets/javascripts/ratyrate.js.erb:

$.fn.raty.defaults.path = "/images/ratyrate";
lyminhtanh commented 5 years ago

This works for me

Give me stars: <%= rating_for @user, 'reputation', star: 10, disable_after_rate: false, enable_half: true,
                              star_path: '',
                              star_on: asset_path('star-on.png'),
                              star_off: asset_path('star-off.png'),
                              star_half: asset_path('star-half.png'),
                              cancel_off: asset_path('cancel-off.png'),
                              cancel_on: asset_path('cancel-on.png') %>