parameter
parameter

Reputation: 904

using Raty jquery plugin with rails 4.0 scaffold form

I'm trying to use Raty in my rails form "Reviews" by using <script>$('#default').raty();</script>. '1 2 3 4 5' shows up instead of actual stars. I have my jquery.raty.js file is in apps/assets/javascripts and the images for stars in apps/assets/javascripts/images. When I mouse over a number, the console displays:

Started GET "/reviews/star-off.png" for 127.0.0.1 at 2014-03-17 17:50:04 -0400 Processing by ReviewsController#show as PNG Parameters: {"id"=>"star-off"} Review Load (2.8ms) SELECT "reviews".* FROM "reviews" WHERE "reviews"."id" = $1 LIMIT 1 [["id", "star-off"]] Completed 404 Not Found in 5ms ActiveRecord::RecordNotFound (Couldn't find Review with id=star-off): app/controllers/reviews_controller.rb:67:in `set_review'

It appears that it's trying to pull the image as part of the reviews controller...but it's really just an image for the jquery plugin. Does anyone have any suggestions? Thanks

Upvotes: 2

Views: 927

Answers (2)

flaviomestre
flaviomestre

Reputation: 61

If it helps, I had to do the following to get it to work properly for me:

$('#star').raty({
  starOn: '<%= image_path('star-on.png') %>',
  starOff: '<%= image_path('star-off.png') %>',
  path: '',
  scoreName: 'star',
  space: true 
});

Upvotes: 3

cat3045
cat3045

Reputation: 295

Tell raty where the images are, like such:

<script>
    $('#default').raty({
      readOnly: true,
      halfScore: true,
      score: 3,
      path: '/assets'
    });
</script>

The code above is working for me, with my images inside the folder app/assets/images. I had a problem with paths myself.

On a relevant note: Inside assets, there's a folder called images and one called javascript and I think they should only hold what they claim. For example, the images folder should only have images inside while the javascript folder should only have javascript files inside. It makes it easier for others who look or work on your code to know where everything is.

Upvotes: 1

Related Questions