mongoid

Mongoid same embedded documents types for different fields

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:28:55
问题 I am attempting to add embedded documents. I know this syntax is wrong but it demonstrates what I am trying to accomplish. class Email include Mongoid::Document embeds_many :recipients, as: :to embeds_many :recipients, as: :cc embeds_many :recipients, as: :bcc field :from, type: String field :subject, type: String field :body, type: String end class Recipient include Mongoid::Document field :email_address, type: String field :name, type: String validates :email_address, :presence => true

gem-install of mongoid throws an uninitialized constant in Ruby, works in irb

你说的曾经没有我的故事 提交于 2019-12-13 08:37:21
问题 I am writing a script with Ruby/MongoDB that stores Tweets. After I gem-installed mongoid , this first-steps code throws an error: require 'rubygems' require 'mongo' require 'mongoid' Mongoid.database = Mongo::Connection.new('localhost').db('db') # snippet from http://rujmah.posterous.com/using-mongoid-without-rails NB. This is no Rails app , but a Terminal script. The error I get is: ./mongoid.rb:10: uninitialized constant Mongoid (NameError) from /Library/Ruby/Site/1.8/rubygems/custom

Insert many mongo - continue on error ruby / Ruby Mongo equivalent for mysql insert ignore

[亡魂溺海] 提交于 2019-12-13 08:27:37
问题 Hi when I try to do continue on error for insert many it doesnt work in mongoid. I set the following unique index db.push_notifications.createIndex({ actor_vid: 1,campaign_id: 1 },{ unique: true, partialFilterExpression: { campaign_id: { $exists: true } } }) PushNotification.collection.insert_many([{:campaign_id => "1",:actor_vid => 9},{:campaign_id => "1",:actor_vid => 8}],:continue_on_error => true, :safe => false) PushNotification.collection.insert_many([{:campaign_id => "1",:actor_vid =>

RoR : Mongoid and form create hash

自作多情 提交于 2019-12-13 05:47:58
问题 Simple question for Rails gurus. Why I do have to use the following statement to insert a new Mongoid document : params[:video][:description] in the following create method of my VideosController? Why I can't use the params[:description] from the POST form? If I use it, the value becomes nil. def create @video = Video.new( :title => params[:video][:title], :description => params[:video][:description] ) if @video.save render 'success' else render 'error' end end Here is the Video.rb class :

Rails & Mongoid - Merging multiple criteria

故事扮演 提交于 2019-12-13 05:23:54
问题 It took me a bit to figure this out and I'm sure others out there are curious how to do this as well.. I have a case where I need to run an .and() query using user input that I converted to an array. My problem was that the query was searching each and every field for BOTH words that was read in from the input. 回答1: So what I did is broke up the queries based on the fields. I.e. if you have the fields :tags, :story, :author you would have 3 queries, tag_query = Book.any_in(:tags => @user

Association in rails using mongodb as database

大憨熊 提交于 2019-12-13 04:49:16
问题 I am using devise. It gives the current userid as current_user.id There are many users. There is a controller name as empsals_controller.rb class EmpsalsController < ApplicationController def index @empsals = Empsal.all end def show @empsal = Empsal.find(params[:id]) end def new @empsal = Empsal.new end def edit @empsal = Empsal.find(params[:id]) end def create @empsal = Empsal.new(params[:empsal]) respond_to do |format| if @empsal.save format.html { redirect_to @empsal, notice: 'Empsal was

mongoid - mongodb, mapreduce get scope varriable or pass it to output

半世苍凉 提交于 2019-12-13 04:46:07
问题 In mapreduce I have a scope total_count to calculate something after grouping something. How can I get back the that scope varriable in output? EDIT: map = %Q{ function() { ttotal_commission += this.commission; tuniq_commission += this.commission; // add first if it not goto reduce emit({ip: this.ip, campaign_id: this.campaign_id}, {commission: this.commission, abc: this.commission}); } } reduce = %Q{ function(key, values) { tuniq_commission += values[0].commission; // add 1 and substract

MiniMagick not working in production

妖精的绣舞 提交于 2019-12-13 04:19:34
问题 I am using MiniMagick gem to crop images and then saving them with mongoid paperclip. Everything seems to be working perfectly in development but in production I am getting the error "ActionView::Template::Error (uninitialized constant Model Name ::MiniMagick)". these are the lines giving the error inside the model: def profile_geometry img = MiniMagick::Image.open(avatar.path) @geometry = {:width => img[:width], :height => img[:height] } end Any help would be hugely appreciated. EDIT:

Mongoid_slug Rails 4 update / destroy object

痞子三分冷 提交于 2019-12-13 02:30:08
问题 I am using mongoig_slug gem in my rails app. I can create an object with the proper url but I can't update / delete the object and I have no error message in the console. (I can edit the form, which contains the correct data) I even used PRY to check in the console and when I check @book exits and is correct, if I do @book.destroy it says true but does not destroy. For the edit, I also checked @book, I also checked book_params which is correct. class Book include Mongoid::Document include

Ruby on Rails - How to delegate error messages from nested model

被刻印的时光 ゝ 提交于 2019-12-13 02:26:43
问题 class User include Mongoid::Document has_many :images accepts_nested_attributes_for :image end class Image include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paperclip has_mongoid_attached_file :uploaded_image, :path => ":rails_root/public/uploads/:class/:id/:basename.:extension", :url => "public/uploads/" validates_attachment_content_type :uploaded_file, :content_type => "application/png", :message => "error massage" belongs_to :user delegate :url, :path, to: :uploaded