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!