Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:35:58+00:00 2026-06-06T18:35:58+00:00

Essentially, I have a binary voting system Like/Dislike. Thee class is called Like It

  • 0

Essentially, I have a binary voting system Like/Dislike. Thee class is called Like It has polymorphic associations to likeable:

class Like < ActiveRecord::Base
     belongs_to :likeable, polymorphic: true
end

and we have the class Comment, which also has polymorphic associations to commentable and can be liked

class Comment < ActiveRecord::Base
     belongs_to :commentable, polymorphic: true
     has_many :likes, :as :likeable
end

We have the class Section, which can also be liked and commented on

class Section < ActiveRecord::Base
    has_many :likes, as: :likeable
    has_many :comments, as: commentable
end

However, on the page section#show I display the Section information, the section likes, and then the comments (from a comments/comments partial). Here is the Section#show view:

<h1><%= exercise.name %></h1>
<p><%= exercise.description %></p>
<%= render 'likes/like_button' %>
<%= render 'comments/comments' %>
<%= render 'comments/comment_form' %>

However, I want the ability to vote on each comment.

The following code is from the _comments.html.erb – What currently doesn’t work is the rendering of the _like_button.html.erb because it doesn’t apply to the comment at hand.

<% @comments.each do |comment| %>
    <%= comment.content %>
    <%= render 'likes/like_button' %>
<hr />
<% end %>

And here is the _like_button.html.erb partial

<% if @like.nil? %>
    <%# No record of Like in table %>
    <%= form_for [@likeable, Like.new] do |f| %>
    <%= f.submit "Like" %>
    <%= f.submit "Dislike" %>
    <% end %>
<% else %>
    <%# Marks current chosen option, if the opposite option is chosen, the record is updated to reflect the descion by the user %>
    <%= form_for [@likeable, @like] do |f| %>
        <% if @like.is_liked %>
            Currently Liked!
            <%= f.submit "Dislike" %>
        <% else %>
            <%= f.submit "Like" %>
            Currently Disliked!
        <% end %>
    <% end %>
<% end %>

So ultimately, I just want to know how to make it possible to vote on a comment from within the Section#show view
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:35:59+00:00Added an answer on June 6, 2026 at 6:35 pm

    Try this:

    <% @comments.each do |comment| %>
        <%= comment.content %>
        <%= render 'likes/like_button', :like => comment.like, :likeable => comment %>
    <hr />
    <% end %>
    
    <% if like.nil? %>
        <%# No record of Like in table %>
        <%= form_for [likeable, Like.new] do |f| %>
        <%= f.submit "Like" %>
        <%= f.submit "Dislike" %>
        <% end %>
    <% else %>
        <%# Marks current chosen option, if the opposite option is chosen, the record is updated to reflect the descion by the user %>
        <%= form_for [likeable, like] do |f| %>
            <% if like.is_liked %>
                Currently Liked!
                <%= f.submit "Dislike" %>
            <% else %>
                <%= f.submit "Like" %>
                Currently Disliked!
            <% end %>
        <% end %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Essentially I have a method of a class called killProgram, which is intended to
I have a class essentially: public class WindowEvent extends Event { public static const
Essentially I would like to have a messages.properties files external to the jar files
I have the code which reads a set of binary files which essentially consist
I have a C++ class that writes its data out to a binary std::ofstream
At the moment I essentially have: A.php: class A { ... } A1.php: class
Essentially I have an NSMutableArray which contains several NSDictionaries . I wish to sort
Essentially I have a script which acts as a task wrapper and emails a
I have essentially the same problem discussed here: http://khason.net/blog/dependency-property-getters-and-setters-in-multithreaded-environment/ public static readonly DependencyProperty MyPropertyProperty
I'm trying to build a Hibernate layer for a database schema I have essentially

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.