mongoid

Mongoid doesn't update position field

对着背影说爱祢 提交于 2019-12-08 11:02:59
问题 I want to be able update Attachinary::File position field I use ruby 2.5.0, rails 5.2.2, mongoid, 'jquery-ui-rails' and custom Attachinary (https://github.com/ipatovanton/attachinary/tree/position) for images upload. application.js jQuery(function() { $(document).on('turbolinks:load', function(){ $('.attachinary-input').attachinary() $("#images").sortable({ update: function(e, ui) { Rails.ajax({ url: $(this).data("url"), type: "PATCH", data: $(this).sortable('serialize'), }); } }); }); })

How can I do “rake db:migrate” with mongoid and active record?

不羁岁月 提交于 2019-12-08 09:50:20
问题 I want to migrate active record (mysql) database. I use database both mongoid and active record. I typed this code. rails generate active_record:migration CreateUsersTable It worked. But I can't migrate it with active_record. How can I migrate active record like rake active_record:db:migrate ? 回答1: I found my problem. I missed adding active_record/railtie to application.rb After I added following line, it works! require "active_record/railtie" 回答2: I experimented with mixing both AR and

will_paginate helper undefined in sinatra with mongoid

China☆狼群 提交于 2019-12-08 08:57:47
问题 I am using sinatra 1.4.3 and mongoid 3.1.4. I tried adding will_paginate gem from master branch for mongoid support so I added this to my gemfile: gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'master' In environment.rb I added: require 'will_paginate' require 'will_paginate/mongoid' And pagination method started working. I have still problem with will_paginate helper. In my views I get errors like: NoMethodError: undefined method `will_paginate' for #

Change type of field in Mongoid without losing data

 ̄綄美尐妖づ 提交于 2019-12-08 06:31:29
问题 How can I run a migration to change the type of a field in Mongoid/MongoDB without losing any data? In my case I'm trying to convert from a BigDecimal (stored as string) to an Integer to store some money. I need to convert the string decimal representation to cents for the integer. I don't want to lose the existing data. I'm assuming the steps might be something like: create new Integer field with a new name, say amount2 deploy to production and run a migration (or rake task) that converts

Limit aggregation in grouped aggregation

和自甴很熟 提交于 2019-12-08 06:26:08
问题 I had a collection like this, but with much more data. { _id: ObjectId("db759d014f70743495ef1000"), tracked_item_origin: "winword", tracked_item_type: "Software", machine_user: "mmm.mmm", organization_id: ObjectId("a91864df4f7074b33b020000"), group_id: ObjectId("20ea74df4f7074b33b520000"), tracked_item_id: ObjectId("1a050df94f70748419140000"), tracked_item_name: "Word", duration: 9540, } { _id: ObjectId("2b769d014f70743495fa1000"), tracked_item_origin: "http://www.facebook.com", tracked_item

Whenever ruby scheduler doesn't work, what am I missing?

百般思念 提交于 2019-12-08 06:08:58
问题 Cannot make it works ... In my config/schedule.rb I have : set :output, '../log/development.log' every 5.minutes do runner "UserWatchedRepo.update" end Note the log setted, but nothing happen. In my Rails 3.0.10 model file app/models/user_watched_repo.rb I get : class UserWatchedRepo include Mongoid::Document def update conn = FaradayStack.build 'https://api.github.com' User.all.map do |user| nickname = user.nickname resp = conn.get "/users/#{nickname}/watched" resp.body.each do |repo| user

How to populate data into mongodb using rails?

假如想象 提交于 2019-12-08 06:03:37
问题 I'm new to rails application. I got connection with mongodb using mongoid. I generated the mongoid:migration using command called rails generate migration sample it creates, db\migrate\20111222081138_sample.rb contains the following code class Sample < Mongoid::Migration def self.up sample.create(first_name: "Heinrich", last_name: "Heine") end def self.down end end my questions are 1.why schema.rb is not present in db. 2.how to populate data into mongodb using rails 3.how to list db

Embedding message replies inside message parent with mongodb using mongoid

不羁岁月 提交于 2019-12-08 04:55:37
问题 I think it's a best practice to embed replies to a specific message inside that message and I'm trying to implement it using mongoid. here is what I have class Message include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paranoia field :subject field :body field :sender_deleted, :type => Boolean, :default => false field :recipient_deleted, :type => Boolean, :default => false field :read_at, :type => DateTime referenced_in :sender, :class_name => "User", :inverse_of =>

In MongoDB, how does on get the value in a field for an embedded document, but query based on a different value

◇◆丶佛笑我妖孽 提交于 2019-12-08 04:54:51
问题 I have a basic structure like this: > db.users.findOne() { "_id" : ObjectId("4f384903cd087c6f720066d7"), "current_sign_in_at" : ISODate("2012-02-12T23:19:31Z"), "current_sign_in_ip" : "127.0.0.1", "email" : "something@gmail.com", "encrypted_password" : "$2a$10$fu9B3M/.Gmi8qe7pXtVCPu94mBVC.gn5DzmQXH.g5snHT4AJSZYCu", "last_sign_in_at" : ISODate("2012-02-12T23:19:31Z"), "last_sign_in_ip" : "127.0.0.1", "name" : "Trip Jameson", "sign_in_count" : 100, "usertimes" : [ ...thousands and thousands of

Access subcollection in mongoid with rails form to edit and create new entry

三世轮回 提交于 2019-12-08 04:37:25
问题 I am using mongodb with mongoid in rails3. I am newbie to all this. My models are as shown below. class Californium include Mongoid::Document field :first_name field :License_type Field :Licese_expiry_date embeds_one :address end class Address include Mongoid::Document field :street field :city field :state field :zip embedded_in :Californium, :inverse_of => :address end My Controller class CaliforniaController < ApplicationController def index @california = Californium.all respond_to do