0

I'm using the jQuery plugin Raty for my ruby on rails 4.0 application and it seems to be working except the images for the stars aren't loading onto the screen.

enter image description here

So those images should be stars ^ When I mouseover them in the console while running web brick the following is outputted. (My scaffold is called reviews)

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

I currently have the star images in apps/assets/javascripts/images but have also tried to put them in app/assets/images and app/views/reviews but they still won't show up. Is my issue that they aren't in the correct directory (and if so, which directory should they be in) or do I need to add some code manually to my reviews controller? Thanks.

edit: So when I try to use it in my index page, I only get an error saying this, so I must have to do something to my routes.rb file?

ActionController::RoutingError (NNo route matches [GET] "/star-off.png")

edit: as requested here is routes.rb

ConcertReview::Application.routes.draw do
resources :reviews

get "review/index"
get "review/artist"
get "review/date"
get "review/venue"
get "review/genre"
get "review/comments"

root 'reviews#index'

get 'reviews/' => 'reviews#index'
end

and here's reviews_controller.rb (autogenerated from scaffold and have not modified)

class ReviewsController < ApplicationController
  before_action :set_review, only: [:show, :edit, :update, :destroy]

  # GET /reviews
  # GET /reviews.json
  def index
    @reviews = Review.all
  end

  # GET /reviews/1
  # GET /reviews/1.json
  def show
  end

  # GET /reviews/new
  def new
    @review = Review.new
  end

  # GET /reviews/1/edit
  def edit
  end

  # POST /reviews
  # POST /reviews.json
  def create
    @review = Review.new(review_params)

    respond_to do |format|
      if @review.save
        format.html { redirect_to @review, notice: 'Review was successfully created.' }
        format.json { render action: 'show', status: :created, location: @review }
      else
        format.html { render action: 'new' }
        format.json { render json: @review.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /reviews/1
  # PATCH/PUT /reviews/1.json
  def update
    respond_to do |format|
      if @review.update(review_params)
        format.html { redirect_to @review, notice: 'Review was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @review.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /reviews/1
  # DELETE /reviews/1.json
  def destroy
    @review.destroy
    respond_to do |format|
      format.html { redirect_to reviews_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_review
      @review = Review.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def review_params
      params.require(:review).permit(:artist, :venue, :date, :genre, :sound, :stagePresence, :songSelection, :overallRating, :comments)
    end
end
parameter
  • 894
  • 2
  • 18
  • 35

1 Answers1

0

I had that very same problem on my project. The star images do belong in app/assets/images like you tried. However, you need to pass raty a path option like such:

$('div').raty({
  readOnly: true,
  halfScore: true,
  score: 3, 
  path: '/assets'
});

This is working for me.

Also, if you have turbolinks on, you're going to have to tweek any $(document).ready(function () {...}); you might have. That was the problem I had right after this one.

cat3045
  • 295
  • 2
  • 11