Comments and Rating section no longer showing up; - ruby-on-rails

I am working on creating a test shoe store website for one of my classes. I had previously added a comment section and rating system for new shoes. For some reason the comment and rating section is no longer viewable.
Here is my product show page
<p id="notice"><%= notice %></p>
<div class="show-buttons" id="show1">
<%= link_to 'Edit', edit_product_path(#product), class: "btn btn- success btn-xs" %> |
<%= link_to 'Back', products_path, class: "btn btn-primary btn-xs" %>
</div>
<div class="pay button">
<%= form_tag "/payments/create" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<%= hidden_field_tag(:product_id, #product.id) %>
</div>
<p>
<strong>Name:</strong>
<%= #product.name %>
</p>
<p>
<strong>Description:</strong>
<%= #product.description %>
</p>
<p>
<strong>Image url:</strong>
<%= #product.image_url %>
</p>
<p>Average Rating:
<div class="rated" data-score="<%= #product.average_rating %>"></div>
</p>
<%= render 'new_comment' %>
<%= render 'comment' %>
<%= will_paginate #comments %>
</div>
<% end %>
Here is my _comment.html.erb
<div class="container">
<div class="row">
<div class="product-reviews">
<% #comments.each do |comment| %>
<div class="row">
<hr>
<p><%= comment.user.first_name %> <small><em><%= "# {time_ago_in_words(comment.created_at)} ago" %></em></small></p>
<% if signed_in? && current_user.admin? %>
<%= link_to ('<span class="glyphicon glyphicon-remove"> </span>').html_safe, product_comment_path(#product, comment), method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
<div class="rated" data-score="<%= comment.rating %>"></div>
<p><%= "Rating: #{comment.rating}/5" %></p>
<p><%= comment.body %></p>
</div>
<% end %>
</div>
</div>
My _new_comment.html.erb
<% if signed_in? %>
<h4>Add a review:</h4>
<%= form_for([#product, #product.comments.build]) do |f| %>
<p>
<%= f.label :body, "Comments" %><br>
<%= f.text_area :body %>
</p>
<p>
<%= f.label :rating %><br>
<div class= "rating"></div>
</p>
<%= f.submit "Submit", class: "btn btn-default" %>
</p>
<% end %>
<% end %>
And finally my product.html.erb
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="productbox">
<div class="imgthumb img-responsive">
<%= image_tag(product.image_url, :class => 'list_image') %>
</div>
<div class="caption">
<h3><%= product.name %></h3>
</div>
</div><!--end productbox-->
</div><!--end columns-->
<div class="col-md-8" id="descriptionp">
<p><%= product.description %><br><br>
<%= product.color %><br><br>
€<%= product.price %><br><br>
<%= link_to 'More Info', product %><br><br>
<% if signed_in? && current_user.admin? %>
<%= link_to 'Edit', edit_product_path(product) %> |
<%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
</p>
</div>
</div><!--/row-->
</div><!--/container -->
<hr>
Any assistance on why I can no longer view my comments or rating page would be greatly appreciated.

Related

Issues with Trix editor in Rails

I'm having this issue with the Trix editor in rails 5.2.4 with webpacker.
The only thing I can see is a little box at the left of the 'Save' button.
My Gemfile has this gem installed:
gem'actiontext',github:'kobaltz/actiontext',branch:'archive',require:'action_text'
And installed the trix editor with:
rails action_text:install
And finally, this is the html code:
<div class="row">
<div class="col-md-3">
<%= link_to 'Back', posts_path, class:'btn btn-secondary mb-4' %>
<div class='card'>
<div class='card-body'>
<h4 class='card-title'>Editing post</h4>
<%= render 'form', post: #post %>
</div>
</div>
</div>
<div class="col-md-9">
<div class="mb-3">
<%= form_with(model: [#post, #paragraph]) do |form| %>
<%= form.hidden_field :element_type, value: 'paragragh' %>
<%= form.submit 'Paragraph', class: "btn btn-primary" %>
<% end %>
</div>
<% #post.elements.each do |element| %>
<% if element.persisted? %>
<%= form_with(model: [#post, element]) do |form| %>
<%= form.rich_text_area :content %>
<%= form.submit 'Save', class: "btn btn-primary" %>
<% end %>
<% end %>
<% end %>
</div>

syntax error, unexpected keyword_ensure, expecting keyword_end in my app

Please i need help validating this code.
Using Ruby 2.3.3 & Rails 5.2
i think all ending anchors are given though
<% if current_user.id != user.id %>
<div class="panel panel-default">
<div class="pane-body">
<center>
<% if !current_user.following?(user) %>
<%= form_for(current_user.active_relationships.build) do |f| %>
<div><%= hidden_field_tag :followed_id, user.id %></div>
<%= f.submit "Follow", class: "btn btn-primary" %>
<% end %>
<% else %>
<%= form_for(current_user.active_relationships.find_by(followed_id: user.id),
html: {method: :delete}) do |f| %>
<%= f.submit "Unfollow", class: "btn btn-default" %>
<% end %>
</center>
</div>
</div>
<% end %>
Here
<% else %>
<%= form_for(current_user.active_relationships.find_by(followed_id: user.id), html: {method: :delete}) do |f| %>
<%= f.submit "Unfollow", class: "btn btn-default" %>
<% end %>
</center>
You have the end to close the block for form_for but not for ending the if-else
<% else %>
<%= form_for(current_user.active_relationships.find_by(followed_id: user.id), html: {method: :delete}) do |f| %>
<%= f.submit "Unfollow", class: "btn btn-default" %>
<% end %>
<% end %>
</center>
Properly indenting helps a lot:
<% if current_user.id != user.id %>
<div class="panel panel-default">
<div class="pane-body">
<center>
<% if !current_user.following?(user) %>
<%= form_for(current_user.active_relationships.build) do |f| %>
<div><%= hidden_field_tag :followed_id, user.id %></div>
<%= f.submit "Follow", class: "btn btn-primary" %>
<% end %>
<% else %>
<%= form_for(current_user.active_relationships.find_by(followed_id: user.id), html: {method: :delete}) do |f| %>
<%= f.submit "Unfollow", class: "btn btn-default" %>
<% end %>
<% end %>
</center>
</div>
</div>
<% end %>
Your end on line 13 closed off the form_for do |f| block, meaning you needed one more to close off the if \ else do block

Rails Syntax Error: expecting keyword end

I get this error: app/views/topics/show.html.erb:49: syntax error, unexpected keyword_ensure, expecting keyword_end. I don't have a line 49. I checked to see if I was missing any <% end %> and I find that I don't.
<h1><%= #topic.name %></h1>
<% if user_is_authorized_for_topics? || if user.moderator? %>
<%= link_to "Edit Topic", edit_topic_path, class: 'btn btn-success' %>
<% end %>
<% if user_is_authorized_for_topics?%>
<%= link_to "Delete Topic", #topic, method: :delete, class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete this topic?' } %>
<% end %>
<div class="row">
<div class="col-md-8">
<p class="lead"><%= #topic.description %></p>
<% #topic.posts.each do |post| %>
<div class="media">
<div class="media-body">
<h4 class="media-heading">
<%= link_to post.title, topic_post_path(#topic, post) %>
</h4>
<small>
submitted <%= time_ago_in_words(post.created_at) %> ago by <%= post.user.name %> <br>
<%= post.comments.count %> Comments
</small>
</div>
</div>
<% end %>
<% #topic.sponsored_posts.each do |sponsored_post| %>
<div class="media">
<div class="media-body">
<h4 class="media-heading">
<%= link_to sponsored_post.title, topic_sponsored_post_path(#topic, sponsored_post) %>
</h4>
<small>
submitted <%= time_ago_in_words(sponsored_post.created_at) %> ago <br>
</small>
</div>
</div>
<% end %>
</div>
<% if current_user %>
<div class="col-md-4">
<%= link_to "New Post", new_topic_post_path(#topic), class: 'btn btn-success' %>
</div>
<% end %>
</div>
Probably this line:
<% if user_is_authorized_for_topics? || if user.moderator? %>
You only need if once, like this:
<% if user_is_authorized_for_topics? || user.moderator? %>

simple form - Reddit-like site

I completed a search and found this topic that is close, How do I make simple form to use, I'm too new to fully understand
what I was looking at.
The answer was as follows:
Step 1
rails generate simple_form:install --bootstrap (which I did after adding the Gem and running Bundle Install)
Step 2
Told me to add wrappers (not sure if I need to complete this step)
Step 3
modify the simple_form and has this example:
<%= simple_form_for(#contact, url: supplier_contacts_path, html: { class:
'form-horizontal' }) do |f| %>
<div class="form-inputs">
<%= f.input :c_regular,wrapper: :horizontal_input_group do %>
<span class="input-group-addon">$</span>
<%= f.input_field :c_regular, :label => "Regular",class: "form-control" %>
<% end %>
</div>
<% end %>
My code is as follows(views/comments/show.html.erb):
<div id="comments">
<%= render :partial => #link.comments %>
</div>
<%= simple_form_for(#link, html {class: 'form-horizontal' }) do |f| %>
<div class="field">
<%= f.text_area :body, size: "60x12" %>
</div>
<%= f.submit "Add Comment", class: 'btn btn-primary" %>
<% end %>
Here's my partial(views/comments/_comments.html.erb):
<%= div_for(comment) do %>
<div class="comments_wrapper clearfix">
<div class="pull-left">
<p class="lead"><%= comment.body %></p>
<p><small>Submitted <strong><%= time_ago_in_words(comment.created_at) %>
ago</strong> by
<%= comment.user.email %></small></p>
</div>
<div class="btn-group pull-right">
<% if comment.user == current_user %>
<%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you
sure?' }, class: "btn btn-sm btn-default" %>
<% end %>
<% end %>
</div>
<% end %>

Rails - Kaminari - paginate_array returns duplicate records

I'm trying to paginate the following array. At the moment the table is being appended to, but only with the same records as the first page:
def collection
#collection ||= begin
viewable_pupils.where(level: level, group_id: group_id).ordered
.map{ |p| Schools::Admin::PupilReportTableFacade.new(p, school.calendar_range_for_year_starting(report_start_year)) }
end
#collection = Kaminari.paginate_array(#collection).page(params[:page]).per(10)
end
helper_method :collection
My view is as follows:
<div class="container">
<%= render 'schools/admin/reporting/collection_partial' %>
</div>
<%= link_to 'Load More', school_reporting_load_more_path, remote: true, id: "load_more_link", class: 'btn btn-info' %>
And the partial being rendered:
<% collection.each do |pupil| %>
<div class="well well--bordered well--skinny well--collapse-pad well--shadow">
<div class="marking-header marking-header--table marking-header--table-even">
<div class="marking-header__cell">
<%= pupil.first_name %>
</div>
<div class="marking-header__cell"><%= pupil.last_name %></div>
<div class="marking-header__cell" align="center">
<% pupil.histories.each do |history| %>
<% next unless school.calendar_range_for_year_starting(report_start_year).cover?(history[:created_at]) %>
<%= history[:year] %> <%= history[:level] %>
<%= history[:created_at] %>
<% end %>
</div>
<div class="marking-header__cell">
<%= "Total completed: #{pupil.pupil.activities_completed_year_starting(report_start_year)}" %></br>
<%= "(#{pupil.pupil.comprehensions_completed_year_starting(report_start_year)} x comprehensions)" unless pupil.pupil.comprehensions_completed_year_starting(report_start_year).zero? %></br>
<%= "(#{pupil.pupil.crosswords_completed_year_starting(report_start_year)} x crosswords)" unless pupil.pupil.crosswords_completed_year_starting(report_start_year).zero? %></br>
<%= "(#{pupil.pupil.debates_completed_year_starting(report_start_year)} x debates" unless pupil.pupil.debates_completed_year_starting(report_start_year).zero? %></br>
<%= "(#{pupil.pupil.word_definitions_completed_year_starting(report_start_year)} x word definitions" unless pupil.pupil.word_definitions_completed_year_starting(report_start_year).zero? %>
<div class="gems">
<% pupil.milestone_badges.each do |badge| %>
<%= image_tag image_path(badge.image), class: 'gem' %>
<% end %>
</div>
</div>
<div class="marking-header__cell">
<input type="checkbox" name="pupils[]" value="<%= pupil.id %>" class="tick-check" id="check-<%= pupil.id %>" data-behaviour="update-compare-count">
<label for="check-<%= pupil.id %>"></label>
<%= "Total this year: #{pupil.pupil.total_points_this_year}" %></br>
<%= "(Total all time: #{pupil.pupil.total_points})" %></br></br>
<%= "iHub points: #{pupil.pupil.score}" %></br>
<%= "Teacher Points: #{pupil.pupil.total_points_year_starting(report_start_year)}" %></br>
<%= "Words Read: #{pupil.pupil.words_read_year_starting(report_start_year)}" %></br>
</div>
</div>
</div>
<% end %>
Finally my ajax:
$('.container').append("<%= escape_javascript(render 'schools/admin/reporting/collection_partial')%>");
$('#load_more_link').replaceWith("<%= escape_javascript(link_to 'Load More', school_reporting_load_more_path, remote: true, id: "load_more_link", class: 'btn btn-info')%>");
If any more info is needed please ask, I feel I've tried everything I can think of at this point.

Resources