mongoid

Mongoid fails on ruby 1.9.3

孤者浪人 提交于 2020-01-13 08:35:13
问题 So I'm playing around with mongo stuffs. Created a new heroku app, added a mongolab option to it, but every mongoid method fails. I googled around, and it looks like this issue was common with ruby prior to 1.9.3, but I'm running 1.9.3. Here's the simplest failing sample: require 'sinatra' require 'mongoid' require 'json' require "sinatra/reloader" if development? Mongoid.load!("mongoid.yml") class Company include Mongoid::Document field :code, type: String field :sector, type: String field

Connection refused - connect(2) with rake db:seed on Mongodb

馋奶兔 提交于 2020-01-12 19:38:35
问题 I am using rails 3.2 and mongoid . I make these steps for setting my database: // Add an Admin User (to the admin db) use admin db.addUser("theadmin", "anadminpassword") // Use your database use superuser // Add a user (to your database) db.addUser("John", "passwordForJohn") // show all users: db.system.users.find() // add readonly user (kinda cool) db.addUser("readonly", "passwordForJohn", true) In my mongo.yml I have: production: host: localhost port: 27017 username: John password:

Two 1 - N relations in Mongoid (Rails)

你。 提交于 2020-01-12 08:05:07
问题 The scenario is: How can an Account give ratings to another account? This results in two lists on the Account. Those who I have rated and those who have rated me. (my_ratings and ratings_given) This boils down to: How can multiple 1 - N relationsips to the same entity work in Mongoid? In Mongoid's Docs it says you can use has_many and belongs_to to link the entities together. I currently have this on Account has_many :ratings, :as => "my_ratings" has_many :ratings, :as => "ratings_given" and

get record with at least one associated object

混江龙づ霸主 提交于 2020-01-11 11:37:33
问题 I have the following schema in mongoid : User has many tasks - has_many :tasks Task belongs to user - belongs_to :user How can I get only 10 first users with at least one task? Something like this: User.where(:tasks.ne => [] ).limit(10) 回答1: Your problem is that Mongoid's has_many doesn't leave anything in the parent document so there are no queries on the parent document that will do anything useful for you. However, the belongs_to :user in your Task will add a :user_id field to the tasks

Rails, Cucumber: make object and its associations

99封情书 提交于 2020-01-07 03:42:08
问题 I'm using mongoid, machinist 2 and pickle. But I think, that question is more common. I have an Account model: class Account include Mongoid::Document include Mongoid::Timestamps referenced_in :user end and User: class User include Mongoid::Document include Mongoid::Timestamps references_one :account end I have the following scenario(I set reference_one association): Scenario: Client views his account Given a user with id: "4ceede9b5e6f991aef000007" And the following accounts exist: | user_id

Can I have thread safe per-request configuration for database connection and table_name in ActiveRecord (or Mongoid)?

喜你入骨 提交于 2020-01-06 03:59:04
问题 Also known as the <<"User has many Databases" question.>> The environment My app is modeled like so: user has_many databases database has_many tables table has_many rows row habtm(+value) columns you get the idea! So instead of modelling a database inside a database, I would like to have: a sqlite3 database that holds the users and many sqlite databases for each user Each user will LCRUD his tables in his databases (similar to phpmyadmin) The problem I would like to have thread safe per

Why is mongoid not allowing for the creation of a new embedded document when using a variable?

允我心安 提交于 2020-01-06 03:04:13
问题 I am trying to add a new embedded document after deleting the embedded document. But I get an error when I use: Code u = User.last u.classes.destroy_all u.classes.create(:name => "Philsophy") => NoMethodError: undefined method `create' for []:Array BUT, If I don't use a variable it WORKS. Can someone please explain this to me? I need to use the nested variable version to loop through a result set of hundreds of items. User.last.classes.destroy_all User.last.classes.create(:name => "Philsophy"

Why is mongoid not allowing for the creation of a new embedded document when using a variable?

ぃ、小莉子 提交于 2020-01-06 03:04:08
问题 I am trying to add a new embedded document after deleting the embedded document. But I get an error when I use: Code u = User.last u.classes.destroy_all u.classes.create(:name => "Philsophy") => NoMethodError: undefined method `create' for []:Array BUT, If I don't use a variable it WORKS. Can someone please explain this to me? I need to use the nested variable version to loop through a result set of hundreds of items. User.last.classes.destroy_all User.last.classes.create(:name => "Philsophy"

accessing sub documents on Rails 3 using Mongoid

﹥>﹥吖頭↗ 提交于 2020-01-05 10:09:09
问题 Here you will find Ryan's railscast called Mongoid (revised) . I've created an app following the railscast and put it on https://github.com/tenzan/store.git In this example, product collection has embedded reviews . I was able to add reviews within from rails console and wanted to display on the browser, what I can't figure out. I feel like I have to tweak in the app/controllers/reviews_controller.rb and app/views/reviews/index.html.erb The app was created Rails 3 and ruby 1.9.3p429. Edit: I

Replacement for column_names when using Mongoid with rails 3 and dry_crud

倾然丶 夕夏残阳落幕 提交于 2020-01-05 07:52:07
问题 I've been doing a spike on Rails 3 and Mongoid and with the pleasant memories of the auto scaffolding in Grails I started to look for a DRY view for ruby when I found: http://github.com/codez/dry_crud I created a simple class class Capture include Mongoid::Document field :species, :type => String field :captured_by, :type => String field :weight, :type => Integer field :length, :type => Integer def label "#{name} #{title}" end def self.column_names ['species', 'captured_by', 'weight', 'length