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 9230689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:53:09+00:00 2026-06-18T05:53:09+00:00

I have User and Community models. Community model will be liked by a user

  • 0

I have User and Community models.

Community model will be liked by a user by this command

    if current_user.voted_up_on? @community
        current_user.dislikes @community
    else
        current_user.likes @community
    end

and I’m now trying to fetch all the users who liked @community.
I’m trying to do it with this. But it won’t return correct users.
How can I fix this?

@users =  User.where(:id => @community.likes.map(&:voter_id)).order("last_active_at DESC").limit(10)

I’m using the gem called ‘acts_as_votable’ for this
https://github.com/ryanto/acts_as_votable

  • 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-18T05:53:10+00:00Added an answer on June 18, 2026 at 5:53 am

    That would return AR::Relation

    # Note: I'm not sure that polymorphic fields are: "votable_type" and "votable_id"
    
    class Community
      ...
      def last_liked(limit = 10)
        User.includes(:votes).where(["votes.votable_type = ? AND votes.votable_id = ?", self.class.name, self.id]).order("users.last_active_at DESC").limit(limit)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this thread https://community.jboss.org/thread/202276?tstart=0 where user ramkumarps shows a way to load
I have a joomla website and I use community builder for user registration and
I have User and Teacher models. Teacher belongs_to User and User has_one Teacher. Also
Let's say I have User model and Post model. Post model contains field user_id
In my rails app I have user, school, and course models. I have set
I have four models in my application, defined as follows class User < ActiveRecord::Base
New to this community... I have to say I love this resource though, it's
I have 3 models (Users - Membership - Community) The users can become members
I have a table as follows id comm_id user_id .. This stores user subscriptions
I have user (not administrator) access to some external JMS. I'm failing to view

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.