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

  • Home
  • SEARCH
  • 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 6912925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:09:09+00:00 2026-05-27T09:09:09+00:00

I have simple application on rails with Mongodb(Mondoid mapper). Scaffold posts , and I

  • 0

I have simple application on rails with Mongodb(Mondoid mapper). Scaffold posts, and I trying to implement rating functional. Post has next structure:

> class Post
  include Mongoid::Document
  include Mongoid::Timestamps

  field :title, type: String
  field :description, type: String
  field :rank, type: Integer, default: "0"
  field :voter_up, type: Array, default: []
  field :voter_down, type: Array, default: []  

As you can see there are two field voter_up, _down. It’s to add users, depending on how they voted. self.voter_up << user.id, or self.voter_down << user.id. In database it looks like:

"voter_up" : [
    ObjectId("4ee08b6e405f3d0a29000005"),
    ObjectId("4ee0aaff405f3d0a2900003a")
]

And if user changed his mind and wants to vote contrary. For example in first time user voted UP. And then voted DOWN. In this situation I need to delete this user from array voter_up and add to voter_down. From rails console it works array.delete(object), but if I try that self.voter_up.delete(user.id) in model function – nothing happens. Why?

  • 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-05-27T09:09:09+00:00Added an answer on May 27, 2026 at 9:09 am

    I am afraid that both of your console and modal would work. Because the delete here you are using is a ruby array method not the mongoids. So You need to call save after delete to push the changed array to server.

         self.voter_up.delete(user.id)
         self.save
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple rails 2.3.4 application I am trying to get running with
I have made a simple Rails application that allows people to comment on posts.
In my Rails application I have a simple controller which also has an action
I have simple rails application. Create, delete, edit posts. And I need to rate
I have a simple Rails application with which I am trying to use the
I have created a rails application that has a simple RESTful json API. This
I have a simple rails application in which I'm trying to add a very
I have a Rails simple application that has two main models. A person model
I have created a simple blog application with Ruby on Rails. The applications consists
I have built a very simple blog application using Ruby on Rails. New to

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.