Ratings with Raty not showing up

不打扰是莪最后的温柔 提交于 2019-12-24 21:16:35

问题


So I am following a tutorial and using cloud 9 as my editor. When I run my program and submit a review. Mackenzie's (the person that made the tutorial) review form lets the viewer select stars as their rating. On the other hand, mine only allows the user to put in a number, and the average rating doesn't change.
Here is my _form.html.erb

<%= form_for([@movie, @review]) do |f| %>
  <% if @review.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@review.errors.count, "error") %> prohibited this review from being saved:</h2>

      <ul>
      <% @review.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :rating %><br>
    <%= f.text_field :rating %>
  </div>
  <div class="field">
    <%= f.label :comment %><br>
    <%= f.text_area :comment %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

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


And my reviews controller:

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

  def new
    @review = Review.new
  end

  def edit
  end

  def create
    @review = Review.new(review_params)
    @review.user_id = current_user.id
    @review.movie_id = @movie.id

    if @review.save
      redirect_to @movie
    else
      render 'new'
    end
  end

  def update
    @review.update(review_params)
  end

  def destroy
    @review.destroy
    redirect_to root_path
  end

  private
    def set_review
      @review = Review.find(params[:id])
    end

    def set_movie
      @movie = Movie.find(params[:movie_id])
    end

    def review_params
      params.require(:review).permit(:rating, :comment)
    end
end


I'm sure that I've installed raty properly. If there's any other code needed to be seen, please contact me. All help appreciated!

来源:https://stackoverflow.com/questions/48013049/ratings-with-raty-not-showing-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!