mongoid

will_paginate helper undefined in sinatra with mongoid

空扰寡人 提交于 2019-12-06 16:48:25
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 #<Class:0x006ff5df8578b0> Am I missing something for helper to work under sinatra? I don't know if it's

How do you seed relationships for Mongoid in Ruby on Rails?

前提是你 提交于 2019-12-06 13:36:16
I'm trying to create a small game server using Ruby on Rails, Mongo, with Mongoid as the ORM, with Devise for authentication. I'm trying to modify the db/seeds.rb to seed several users and game documents. How do you create a seed between two Mongo/Mongoid relationships? I have Users and Games . Users have_many Games. I've found examples of creating a seed database for "embeds_many" and "embedded_in", but not for has / belongs. A follow-up would be if this is the proper architecture (there's a third model "Turns" that will be embedded in the "Game". class Game include Mongoid::Document belongs

Mongodb/Mongoid - what does {:multi => true} mean

…衆ロ難τιáo~ 提交于 2019-12-06 09:42:35
Regarding this question: With Mongoid, can I "update_all" to push a value onto an array field for multiple entries at once? I would like to ask: What's the purpose of {:multi => true} here? Is it possible to push a value into an array when update_all via mongoid now? because the question is in 2010. Thanks. theTRON The documentation for the MongoDB update method states the following: multi - indicates if all documents matching criteria should be updated rather than just one. Can be useful with the $ operators below. So basically the multi parameter is what enables the update_all behaviour in

How to benchmarking mongodb/mongoid scripts, for comparing two different query techniques

跟風遠走 提交于 2019-12-06 09:40:51
Do you have a suggestion on how to test performances over two different mongoid/mongodb query implementations? The implementation to compare, are related to a previous "Q & A" but I'll report those here again, for brevity : first code : Competitor = Struct.new(:html_url, :description, :user) competitors = [] User.all.map do |user| user.watchlists.all.map do |wl| if wl.tags_array == ["ruby", "web", "framework"] competitors << Competitor.new(wl.html_url, wl.description, wl.user.nickname) end end end vs. second code : Competitor = Struct.new(:html_url, :description, :user) competitors = [] User

Reduce the execution time of jobs of sidekiq

我的未来我决定 提交于 2019-12-06 09:29:06
I am currently working on an app which involves syncing of contacts on rails server. I am using redis server and sidekiq for performing contact syncing in the background. My database is mongodb and I am using mongoid gem as ORM. Workflow is a follows: Contacts on the phone are passed to the rails server through app and then on the rails server, it is queued in the redis server. Now cron job triggers sidekiq which connects to redis and completes the job. One Job of sidekiq is as follows: it has array of contacts(size upto 3000). It has to process each of these contacts. By processing I mean

Mongo finders and criteria

倖福魔咒の 提交于 2019-12-06 08:35:57
I use MongoDB in my rails application with Mongoid mapper. But I don't understand finders and criteria of querying. For example in mongoid documentaion in section Finders is query Model.all , but if I use that(for example User.all ), console return criteria and not the result: => #<Mongoid::Criteria selector: {}, options: {}, class: User, embedded: false> But if I use finder Model.first or Model.last , console return specific result. ( User.first return specific user, with its fields, as :email , :username and other). Why Model.all wrote in documentation as finders ? And what I need doing if I

Mongoid and ActiveRecord relations: undefined method `quoted_table_name'

巧了我就是萌 提交于 2019-12-06 08:34:51
问题 class Contest < ActiveRecord::Base has_one :claim_template end class ClaimTemplate include Mongoid::Document belongs_to :contest end # console Contest.new.claim_template #=> NoMethodError: undefined method `quoted_table_name' for ClaimTemplate:Class ok, let's add quoted_table_name to ClaimTemplate : def self.quoted_table_name "claim_templates" end # console Contest.new.claim_template #=> nil # Cool! # But: Contest.last.claim_template #=> TypeError: can't convert Symbol into String So how can

undefined method 'dragonfly_accessor'

我的梦境 提交于 2019-12-06 08:27:11
问题 I am new to dragonfly and trying to go through the setup directions on the main documentation page for rails. Not using Active Record. My steps: 1) add to Gemfile gem 'dragonfly', "~>1.0.3" 2) bundle install 3) rails g dragonfly created initializers/dragonfly.rb 4) model class Post include Mongoid::Document dragonfly_accessor :image field :title, type: String field :body, type: String end 5) controller params.require(:post).permit(:title, :body, :image) Just running mongod and rails s, I get

Is it possible to change default TimeZone in MongoDB using Rails 3?

你说的曾经没有我的故事 提交于 2019-12-06 08:09:28
I have such trouble: when I'm creating object and setting some datetime It is saving database in UTC TimeZone. Here is example: //showing full list of object properties Grant _id: 5108ee29e6b564611400000, start_date: 2013-01-30 09:56:27 UTC //then showing a.start_date Wed, 30 Jan 2013 13:56:27 +0400 I tried to forbid database to use UTC. Here is mongoid.yml: development: options: raise_not_found_error: false sessions: default: use_activesupport_time_zone: true use_utc: false database: test_mongoid_production hosts: - localhost:27017 options: consistency: :strong and in application.rb: config

Can rails scopes filter on the number of associated classes for a given field

故事扮演 提交于 2019-12-06 07:50:49
I am using Rails 3 with Mongoid. I have a Folder class that can then be shared with other User classes as such class Folder has_one :owner has_many :users I am trying to create two scopes one that can be used to return all private folders, and one to return all shared folders. Is there any way to count the number of associations within a scope? scope :personal, where(:users.count => 0) #Erroring on count... scope :shared, where(:users.count.gt => 0) #Erroring on count... I've considered building methods instead but would prefer scopes as I wish to chain them with other scopes. Since you're