0

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!

iiRosie1
  • 162
  • 2
  • 17
  • Does anyone have any easy steps to install raty properly using ruby-on-rails? – iiRosie1 Dec 28 '17 at 19:51
  • What is the expected behavior of the bits of code you are showing. I don't see any obvious flaw, review with rating and comment should be properly saved into database. – Maxence Dec 29 '17 at 00:49
  • @Maxence When you write a review, instead of entering a number for your rating in a text field, you should select stars to show your rating. – iiRosie1 Dec 29 '17 at 13:38

0 Answers0