Search Results

Search found 38 results on 2 pages for 'mongoid'.

Page 1/2 | 1 2  | Next Page >

  • heroku mongohq and mongoid Mongo::ConnectionFailure

    - by Ole Morten Amundsen
    I have added the mongoHQ addon for mongodb at heroku. It crashes with something like this. connect_to_master': failed to connect to any given host:port (Mongo::ConnectionFailure) The descriptions online (heroku mongohq) are more directed towards mongomapper, as I see it. I'm running ruby 1.9.1 and rails 3-beta with mongoid. My feeling says that there's something with ENV['MONGOHQ_URL'], which it says the MongoHQ addon sets, but I haven't set MONGOHQ_URL anywhere in my app. I guess the problem is in my mongoid.yml ? defaults: &defaults host: localhost development: <<: *defaults database: aliado_development test: <<: *defaults database: aliado_test # set these environment variables on your prod server production: <<: *defaults host: <%= ENV['MONGOID_HOST'] %> port: <%= ENV['MONGOID_PORT'] %> username: <%= ENV['MONGOID_USERNAME'] %> password: <%= ENV['MONGOID_PASSWORD'] %> database: <%= ENV['MONGOID_DATABASE'] %> It works fine locally, but fails at heroku, more stack trace: ==> crashlog.log <== Cannot write to outdated .bundle/environment.rb to update it /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/rack-1.1.0/lib/rack.rb:14: warning: already initialized constant VERSION /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongo-0.20.1/lib/mongo/connection.rb:435:in `connect_to_master': failed to connect to any given host:port (Mongo::ConnectionFailure) from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongo-0.20.1/lib/mongo/connection.rb:112:in `initialize' from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4 /lib/mongoid/railtie.rb:32:in `new' from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4/lib/mongoid/railtie.rb:32:in `block (2 levels) in <class:Railtie>' from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4/lib/mongoid.rb:110:in `configure' from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4/lib/mongoid/railtie.rb:21:in `block in <class:Railtie>' from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/railties-3.0.0.beta3/lib/rails/initializable.rb:25:in `instance_exec' ..... It all works locally, both tests and app. I'm out of ideas... Any suggestions? PS: Somebody with high repu mind create the tag 'mongohq'?

    Read the article

  • Ruby. Mongoid. Relations

    - by Scepion1d
    I've encountered some problems with MongoID. I have three models: require 'mongoid' class Configuration include Mongoid::Document belongs_to :user field :links, :type => Array field :root, :type => String field :objects, :type => Array field :categories, :type => Array has_many :entries end class TimeDim include Mongoid::Document field :day, :type => Integer field :month, :type => Integer field :year, :type => Integer field :day_of_week, :type => Integer field :minute, :type => Integer field :hour, :type => Integer has_many :entries end class Entry include Mongoid::Document belongs_to :configuration belongs_to :time_dim field :category, :type => String # any other dynamic fields end Creating documents for Configurations and TimeDims is successful. But when i've trying to execute following code: params = Hash.new params[:configuration] = config # an instance of Configuration from DB entry.each do |key, value| params[key.to_sym] = value # String end unless Entry.exists?(conditions: params) params[:time_dim] = self.generate_time_dim # an instance of TimeDim from DB params[:category] = self.detect_category(descr) # String Entry.new(params).save end ... i saw following output: /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/bson-1.6.1/lib/bson/bson_c.rb:24:in `serialize': Cannot serialize an object of class Configuration into BSON. (BSON::InvalidDocument) from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/bson-1.6.1/lib/bson/bson_c.rb:24:in `serialize' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:604:in `construct_query_message' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:465:in `send_initial_query' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:458:in `refresh' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:128:in `next' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/db.rb:509:in `command' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:191:in `count' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/cursor.rb:42:in `block in count' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/collections/retry.rb:29:in `retry_on_connection_failure' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/cursor.rb:41:in `count' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/contexts/mongo.rb:93:in `count' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/criteria.rb:45:in `count' from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/finders.rb:60:in `exists?' from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:110:in `block (2 levels) in push_entries_to_db' from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:103:in `each' from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:103:in `block in push_entries_to_db' from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:102:in `each' from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:102:in `push_entries_to_db' from main_starter.rb:15:in `<main>' Can anyone tell what am I doing wrong?

    Read the article

  • Dynamic attributes with Rails and Mongoid

    - by japancheese
    Hello, I'm learning MongoDB through the Mongoid Ruby gem with Rails (Rails 3 beta 3), and I'm trying to come up with a way to create dynamic attributes on a model based on fields from another model, which I thought a schema-less database would be a good choice for. So for example, I'd have the models: class Account include Mongoid::Document field :name, :type => String field :token, :type => String field :info_needed, :type => Array embeds_many :members end class Member include Mongoid::Document embedded_in :account, :inverse_of => :members end I'm looking to take the "info_needed" attribute of the Account model and created dynamic attributes on the Member model based on what's inside. If club.info_needed was ["first_name", "last_name"], I'm trying to create a form that would save first_name and last_name attributes to the Member model. However, upon practice, I just keep getting "undefined method first_name=" errors on the Member model when trying to do this. I know MongoDB can handle dynamic attributes per record, but how can I get Mongoid to do this without an undefined method error?

    Read the article

  • stored as array understanding mongoid

    - by Gagan
    Hello frens, This is not a problem, but I just want to know stored as array of Mongoid better. I have following code in my model. class Company include Mongoid::Document include Mongoid::Timestamps references_many :people, :stored_as => :array, :inverse_of => :companies end class Person include Mongoid::Document include Sunspot::Mongoid references_many :companies, :stored_as => :array, :inverse_of => :people end Now in Company object we get person_ids as a result of stored_as array and company_ids in Person object. Now initially I inserted lots of person in company and the ids in person_ids fields is huge. Now I deleted most of person from company down to 8 people. Now I don't get why person_ids fields of Company object storing all the deleted ids of person. My console snapshot is follwing ruby-1.9.2-head Company.first.person_ids = [BSON::ObjectId('4d12d2907adf350695000025'), BSON::ObjectId('4d12d2907adf35069500002c'), BSON::ObjectId('4d12d2907adf350695000035'), BSON::ObjectId('4d12d2907adf35069500003f'), BSON::ObjectId('4d12d2907adf350695000048'), BSON::ObjectId('4d12d2907adf350695000052'), BSON::ObjectId('4d12d2907adf350695000059'), BSON::ObjectId('4d12d2907adf350695000062'), BSON::ObjectId('4d12d4017adf35069500008d'), BSON::ObjectId('4d12d4017adf350695000094'), BSON::ObjectId('4d12d4017adf35069500009d'), BSON::ObjectId('4d12d4017adf3506950000a7'), BSON::ObjectId('4d12d4017adf3506950000b0'), BSON::ObjectId('4d12d4017adf3506950000ba'), BSON::ObjectId('4d12d4017adf3506950000c1'), BSON::ObjectId('4d12d4017adf3506950000ca'), BSON::ObjectId('4d12d48a7adf3506950000f5'), BSON::ObjectId('4d12d48a7adf3506950000fc'), BSON::ObjectId('4d12d48a7adf350695000108'), BSON::ObjectId('4d12d48b7adf350695000115'), BSON::ObjectId('4d12d48b7adf350695000121'), BSON::ObjectId('4d12d48b7adf35069500012e'), BSON::ObjectId('4d12d48b7adf350695000135'), BSON::ObjectId('4d12d48b7adf350695000141'), BSON::ObjectId('4d12d53e7adf35069500016f'), BSON::ObjectId('4d12d53e7adf350695000176'), BSON::ObjectId('4d12d53e7adf350695000182'), BSON::ObjectId('4d12d53e7adf35069500018f'), BSON::ObjectId('4d12d53e7adf35069500019b'), BSON::ObjectId('4d12d53f7adf3506950001a8'), BSON::ObjectId('4d12d53f7adf3506950001af'), BSON::ObjectId('4d12d53f7adf3506950001bb'), BSON::ObjectId('4d12d8587adf3506950001e9'), BSON::ObjectId('4d12d8587adf3506950001f0'), BSON::ObjectId('4d12d8587adf3506950001ff'), BSON::ObjectId('4d12d8597adf35069500020f'), BSON::ObjectId('4d12d8597adf35069500021e'), BSON::ObjectId('4d12d8597adf35069500022e'), BSON::ObjectId('4d12d8597adf350695000235'), BSON::ObjectId('4d12d85a7adf350695000244'), BSON::ObjectId('4d12d9587adf35069500025b'), BSON::ObjectId('4d12db8b7adf35069500026a'), BSON::ObjectId('4d12de6f7adf3509c9000024'), BSON::ObjectId('4d12de6f7adf3509c900002b'), BSON::ObjectId('4d12de6f7adf3509c900003a'), BSON::ObjectId('4d12de707adf3509c900004a'), BSON::ObjectId('4d12de707adf3509c9000059'), BSON::ObjectId('4d12de707adf3509c9000069'), BSON::ObjectId('4d12de707adf3509c9000070'), BSON::ObjectId('4d12de717adf3509c900007f'), BSON::ObjectId('4d12e7f27adf350bd2000009'), BSON::ObjectId('4d12e81f7adf350bd2000015'), BSON::ObjectId('4d12e87f7adf350bd2000024'), BSON::ObjectId('4d12e8b87adf350bd200004c'), BSON::ObjectId('4d12e8b97adf350bd2000053'), BSON::ObjectId('4d12e8b97adf350bd200005c'), BSON::ObjectId('4d12e8b97adf350bd2000066'), BSON::ObjectId('4d12e8b97adf350bd200006f'), BSON::ObjectId('4d12e8b97adf350bd2000079'), BSON::ObjectId('4d12e8ba7adf350bd2000080'), BSON::ObjectId('4d12e8ba7adf350bd2000089'), BSON::ObjectId('4d12ee6b7adf350bd2000198'), BSON::ObjectId('4d12ee6b7adf350bd200019f'), BSON::ObjectId('4d12ee6c7adf350bd20001a5'), BSON::ObjectId('4d12ee6c7adf350bd20001ac'), BSON::ObjectId('4d12ee6c7adf350bd20001b2'), BSON::ObjectId('4d12ee6c7adf350bd20001b9'), BSON::ObjectId('4d12ee6c7adf350bd20001c0'), BSON::ObjectId('4d12ee6c7adf350bd20001c6'), BSON::ObjectId('4d141ca57adf35033e00006e'), BSON::ObjectId('4d141ca57adf35033e000075'), BSON::ObjectId('4d1420aa7adf350705000003'), BSON::ObjectId('4d1420aa7adf35070500000a'), BSON::ObjectId('4d1420f47adf350705000011'), BSON::ObjectId('4d1420f57adf350705000015'), BSON::ObjectId('4d1420f57adf350705000018'), BSON::ObjectId('4d1420f57adf35070500001c'), BSON::ObjectId('4d1420f57adf350705000023'), BSON::ObjectId('4d1420f57adf350705000026'), BSON::ObjectId('4d14215f7adf35070500004b'), BSON::ObjectId('4d14215f7adf350705000052'), BSON::ObjectId('4d14215f7adf350705000055'), BSON::ObjectId('4d14215f7adf350705000059'), BSON::ObjectId('4d14215f7adf35070500005c'), BSON::ObjectId('4d14215f7adf350705000060'), BSON::ObjectId('4d14215f7adf350705000067'), BSON::ObjectId('4d14215f7adf35070500006a')] Company.first.people.collect(&:id) = [BSON::ObjectId('4d14215f7adf35070500004b'), BSON::ObjectId('4d14215f7adf350705000052'), BSON::ObjectId('4d14215f7adf350705000055'), BSON::ObjectId('4d14215f7adf350705000059'), BSON::ObjectId('4d14215f7adf35070500005c'), BSON::ObjectId('4d14215f7adf350705000060'), BSON::ObjectId('4d14215f7adf350705000067'), BSON::ObjectId('4d14215f7adf35070500006a')] Isn't the Company.first.person_ids array be only storing the ids shown by Company.first.people.collect(&:id) It would be helpful if some one tell me when to best use stored_as = :array method. Do stored_as = :array increase querying performance? Thanks

    Read the article

  • restrict documents for mapreduce with mongoid

    - by theBernd
    I implemented the pearson product correlation via map / reduce / finalize. The missing part is to restrict the documents (representing users) to be processed via a filter query. For a simple query like mapreduce(mapper, reducer, :finalize => finalizer, :query => { :name => 'Bernd' }) I get this to work. But my filter criteria is a little bit more complicated: I have one set of preferences which need to have at least one common element and another set of preferences which may not have a common element. In a later step I also want to restrict this to documents (users) within a certain geographical distance. Currently I have this code working in my map function, but I would prefer to separate this into either query params as supported by mongoid or a javascript function. All my attempts to solve this failed since the code is either ignored or raises an error. I did a couple of tests. A regular find like User.where(:name.in => ['Arno', 'Bernd', 'Claudia']) works and returns #<Mongoid::Criteria:0x00000101f0ea40 @selector={:name=>{"$in"=>["Arno", "Bernd", "Claudia"]}}, @options={}, @klass=User, @documents=[]> Trying the same with mapreduce User.collection. mapreduce(mapper, reducer, :finalize => finalizer, :query => { :name.in => ['Arno', 'Bernd', 'Claudia'] }) fails with `serialize': keys must be strings or symbols (TypeError) in bson-1.1.5 The intermediate query parameter looks like this :query=>{#<Mongoid::Criterion::Complex:0x00000101a209e8 @key=:name, @operator="in">=>["Arno", "Bernd", "Claudia"]} and at least @operator looks a bit weird to me. I'm also uncertain if the class name can be omitted. BTW - I'm using mongodb 1.6.5-x86_64, and the mongoid 2.0.0.beta.20, mongo 1.1.5 and bson 1.1.5 gems on MacOS. What am I doing wrong? Thanks in advance.

    Read the article

  • mongoid with rails - Database should be a Mongo::DB, not NilClass"

    - by Adam T
    Greetings I am trying to get Mongoid to work with my Rails app and I am getting an error: "Mongoid::Errors::InvalidDatabase in 'Shipment bol should be unique' Database should be a Mongo::DB, not NilClass" I have created the mongoid.yml file in my config directory and have mongodb running as a daemon. The config file is like so: defaults: &defaults host: localhost development: <<: *defaults database: ship-it-development test: <<: *defaults database: ship-it-test production: <<: *defaults host: <%= ENV['MONGOID_HOST'] % port: <%= ENV['MONGOID_PORT'] % database: <%= ENV['MONGOID_DATABASE'] % All of my specs fail with the above error. I am using rails 2.3.8. Anyone have ideas?

    Read the article

  • How to skip callbacks on Mongoid Documents?

    - by jpemberthy
    My question is similar to this one http://stackoverflow.com/questions/1342761/how-to-skip-activerecord-callbacks but instead of AR I'm using Mongoid, It seems like that isn't implemented yet in the current version of Mongoid, so I'd like to know what should be an elegant solution to implement it. (if necessary).

    Read the article

  • Formtastic with Mongoid embedded_in relations

    - by miah
    Is there any quick way to make a form for embeds_many-embedded_in relation? I have the following: class Team include Mongoid::Document field :name, :type => String embeds_many :players end class Player include Mongoid::Document embedded_in :team, :inverse_of => :players field :name, :type => String end I want to create a form for team with embedded editing for players. Seen https://github.com/bowsersenior/formtastic_with_mongoid_tutorial but "TODO" there.

    Read the article

  • Mongoid or MongoMapper?

    - by PanosJee
    I have tried MongoMapper and it is feature complete (offering almost all AR functionality) but i was not very happy with the performance when using large datasets. Has anyone compared with Mongoid? Any performance gains ?

    Read the article

  • Error handling in Rails Controller for adding embedded Mongoid documents to Model

    - by Dragonfly
    I have a Item model that has embedded documents. Currently, the following comments_controller code will add a comment to the item successfully. However, if pushing the comment document onto the comments array on item fails, I will not know this. #this does work, but i do not know if the push fails def create comment = Comment.new(:text => params[:text]) @item.comments << comment render :text => comment end I would like to have something like this, but @item.comments << comment does not return true or false: #this does not work def create comment = Comment.new(:text => params[:text]) if @item.comments << comment render :text => comment else render :text => 'oh no' end end Nor does it throw an exception when the document push fails: #this does not work def create begin comment = Comment.new(:text => params[:text]) @item.comments << comment render :text => comment rescue Exception => e render :text => 'oh no' end end Thanks!

    Read the article

  • Cucumber testing with rails on mongoid-gridfs

    - by Deepak Lamichhane
    I am getting this weird error while running cucumber test: ERROR Mongo::OperationFailure: Database command 'filemd5' failed: {"errmsg"="exception: best guess plan requested, but scan and order required: query: { files_id: ObjectId('4d1abab3a15c84139c00006e') } order: { files_id: 1, n: 1 } choices: { $natural: 1 } ", "code"=13284, "ok"=0.0} I have a list of similar scenarios, where first scenario passes but all the other following scenario fails. I searched for it and I found that there is problem with indexing. But, I am not sure about what query to write. Furthermore, I can add the query on the mongo of the development. I want to make sure that the indexing is done in test too. If anyone has any idea on this, feel free.

    Read the article

  • Jobs magically disappear from queue (delayed_job mongoid 2 on heroku)

    - by Hayk Saakian
    lets say i do something like arrs = Article.where(:body => nil) i'll have arrs.count is let's say 900 and i do arrs.each do |ar| ar.delay.download_via_diffbot #a method that takes some time, does some http, and writes a non-nil value to ar.body end now i'll watch the logs, and a wait a few minutes on ~5 dynos do the jobs, and do a count again: arrs.count is now ~800 so wtf, i thought i just told my workers to do ~900 jobs, what happened to the other 800? i can confirm that i'm only making ~100 HTTP requests b/c the api reporting shows me this, also simply watching the logs is telling enough that 900 jobs are not happening.

    Read the article

  • How can i generate mongoid.yml config in Rail 2.3.5?

    - by Micke
    As the title says, how can i generate the default mongoid.yml config file on Rail 2.3.5? I try to use te ´rails generate mongoid:config´ command but it just generates a new app. And also, i would like to use has_many in mongoid without embeding the associated model in the same field. I would like them to be in seperate fields and associated through a *_id "column". Is that possible? Thank you, Micke.

    Read the article

  • Rails and Mongoid best way to implement sharing system

    - by Matteo Pagliazzi
    I have to model User and Board in rails using mongoid as ODM. Each board is referenced to an user through a foreign key user_id and now I want to add the ability to share a board with other users. Following CRUD I'd create a new Model called something like Share and it's releated Controller with the ability to create/edit/delete a Share but I have some doubts: First, where to save informations about Shares? I think I may create a field in the Board's collection called shared_with including an array of user ids. in a MySQL I'd created a new table with the ids of who share, the resource shared and the user the resources is shared with but I don't think that's necessary using MongoDB. Every user a Board is shared with should be able to edit the Board (but not to delete it) so the Board should have two relations one with the owner and another with the users the board is shared with, right? For permission (the owner should be able to delete a board but the users it is shared with shouldn't) what to use? I'm using Devise for authentication but I think something like CanCan would fit better. but how to implement it? What do you think about this way? Do you find any problems or have better solutions?

    Read the article

  • How to store UTC time values in Mongo with Mongoid?

    - by Jerry Cheung
    The behavior I'm observing with the Mongoid adapter is that it'll save 'time' fields with the current system timezone into the database. Note that it's the system time and not Rail's environment's Time.zone. If I change the system timezone, then subsequent saves will pick up the current system timezone. # system currently at UTC -7 @record.time_attribute = Time.now.utc @record.save # in mongo, the value is "time_attribute" : "Mon May 17 2010 12:00:00 GMT-0700 (QYZST)" @record.reload.time_attribute.utc? # false

    Read the article

  • How do I update a cumulative field in a Rails database (using ActiveRecord or Mongoid)?

    - by picardo
    I want to update a field in a database table that has to have a cumulative value. So basically I need to find the current value of the field and update it using a new number. My first inefficient try at this (in Mongoid) is: v = Landlord.where(:name=>"Lorem") v.update_attributes(:violations=>v.violations + 10) Is there a simple method than making one query to read, then sum up, and another query to write?

    Read the article

  • How to validates cyrilic email in Rails 3.1?

    - by iKeler
    Let's say I had the email address like putin-crab@?????????.?? How to validate that address in rails 3.1? My Model(i use Mongoid): #encoding: utf-8 class User include Mongoid::Document field :email, :type => String validates :email, :presence => true, :format => { :with => RFC822::EMAIL } end For validations reqexp i use gem https://github.com/dim/rfc-822 in rails console (normal email): ruby-1.9.2-p290 :001 > usr = User.new( :email => "[email protected]" ) => #<User _id: 4ec627cf4934db7e4d000001, _type: nil, email: "[email protected]"> ruby-1.9.2-p290 :002 > usr.valid? => true in rails console (fu@#ing email): ruby-1.9.2-p290 :003 > usr = User.new( :email => "putin-crab@?????????.??" ) => #<User _id: 4ec627f44934db7e4d000002, _type: nil, email: "putin-crab@?????????.??"> ruby-1.9.2-p290 :004 > usr.valid? Encoding::CompatibilityError: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validations/format.rb:9:in `=~' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validations/format.rb:9:in `!~' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validations/format.rb:9:in `validate_each' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validator.rb:153:in `block in validate' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validator.rb:150:in `each' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validator.rb:150:in `validate' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:302:in `_callback_before_13' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:404:in `_run_validate_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:in `run_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:42:in `block in run_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `call' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `run_cascading_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:41:in `run_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validations.rb:212:in `run_validations!' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:390:in `_run_validation_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:in `run_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:42:in `block in run_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `call' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:67:in `run_cascading_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/callbacks.rb:41:in `run_callbacks' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validations/callbacks.rb:53:in `run_validations!' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/activemodel-3.1.1/lib/active_model/validations.rb:179:in `valid?' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/mongoid-2.3.3/lib/mongoid/validations.rb:70:in `valid?' from (irb):4 from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start' from /home/username/.rvm/gems/ruby-1.9.2-p290@rail31/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>' from script/rails:6:in `require'

    Read the article

  • Mongoid Embeds_many won't save on nested form

    - by Brandon J McKay
    I've got an embeds_many association I'm trying to set up which I've done successfully before, but I'm trying to do it all in one nested form and I can't figure it out. Let's say we have a pocket model: class Pocket include Mongoid::Document field :title, type: String embeds_many :coins, cascade_callbacks: true end and a Coin Model: class Coin include Mongoid::Document field :name, type: String embedded_in :pocket end in my form for the pocket, I'm using: = f.fields_for @pocket.coins do |coin| = coin.text_field :name My controller is the default scaffolded controller. When I use the console, it saves fine and I can see the new pocket and coin I've created. But when I try to create or update a coin from the form, the pocket saves but the coin remains unchanged. What am I missing here?

    Read the article

  • error while using cancan in ruby: "uninitialized constant CanCan::Rule::Mongoid"

    - by Ran
    here is my controller: class AdminController < ApplicationController before_filter :require_user authorize_resource :class => false def index end def users_list end end here is my Ability class: class Ability include CanCan::Ability def initialize(user) if user.admin? can :manage, :all else can :read, :all end end end when trying to access "/admin/users_list" (with an admin user or without) i get the following error: uninitialized constant CanCan::Rule::Mongoid any thoughts?

    Read the article

  • How to set ActiveModel::Base.include_root_in_json to false?

    - by Mark L
    I'm using Rails 3 w/ Mongoid, (so no ActiveRecord). Mongoid uses ActiveModel's "to_json" method, and by default that method includes the root object in the JSON (which I don't want). I've tried putting this in an initializer: ActiveModel::Base.include_root_in_json = false But get the error uninitialized constant ActiveModel::Base Any ideas how I can change this? I changed the default directly in the source-code and it worked fine, but obviously I'd like to do it properly. The variable is defined at the top of this file: Github - activemodel/lib/active_model/serializers/json.rb From the docs: "The option ActiveModel::Base.include_root_in_json controls the top-level behavior of to_json. It is true by default."

    Read the article

  • MongoDB, Carrierwave, GridFS and prevention of files' duplication

    - by Arkan
    I am dealing with Mongoid, carrierwave and gridFS to store my uploads. For example, I have a model Article, containing a file upload(a picture). class Article include Mongoid::Document field :title, :type => String field :content, :type => String mount_uploader :asset, AssetUploader end But I would like to only store the file once, in the case where I'll upload many times the same file for differents articles. I saw GridFS has a MD5 checksum. What would be the best way to prevent duplication of identicals files ? Thanks

    Read the article

  • syntax error, unexpected ',', expecting ')' RoR

    - by McDoku
    I am trying to get a collection select from an another model and I keep getting the above error. Looked everywhere, got rails casts but nothing makes sense. _form.rb <%= f.label :city %><br /> <%= f.collection_select (:share ,:city_id, City.all , :id, :name ) %> It highlights 'form' on the error report <h1>New share</h1> <%= render 'form' %> <%= link_to 'Back', shares_path %> Here are my models... class Share include Mongoid::Document field :name, type: String field :type, type: String field :summary, type: String field :description, type: String field :city, type: String embedded_in :city has_many :category end class City include Mongoid::Document embedded_in :share field :name, type: String field :country, type: String attr_accessible :name, :city_id, :id end Searched everywhere and I cannot figure it out. It must be something silly.

    Read the article

  • Building simple Reddit scraper

    - by Bazant Fundator
    Let's say that I would like to make a collection of images from reddit for my own amusement. I have ran the code on my development env and It haven't gone past the first page of posts (anything beyond requries the after string from the JSON. Additionally, When I turn on the validation, the whole loop breaks if the item doesn't pass it, not just the current iteration. I would be glad If you helped me understand mistakes I made. class Link include Mongoid::Document include Mongoid::Timestamps field :author, type: String field :url, type: String validates_uniqueness_of :url, # no duplicates validates :url, uniqueness :true end def fetch (count, after) count_s = count.to_s # convert count to string link = "http://reddit.com/r/aww/.json?count="+count_s+"&after="+after #so it can be used there res = HTTParty.get(link) # GET req. to the reddit server json = JSON.parse(res.body) # Parse the response if json['kind'] == "Listing" then # check if the retrieved item is a Listing for i in 1...(count) do # for each list item datum = json['data']['children'][i]['data'] #i-th element properties if datum['domain'].in?(["imgur.com", "i.imgur.com"]) then # fetch only imgur links Link.create!(author: datum['author'], url: datum['url']) # save to db end end count += 25 fetch(count, json['data']['after']) # if it retrieved the right kind of object, move on to the next page end end fetch(25," ") # run it

    Read the article

  • Does anybody have any tips for managing polymorphic nested resources in Rails 3?

    - by Ryan
    in config/routes.rb: resources posts do resources comments end resources pictures do resources comments end I would like to allow for more things to be commented on as well. I'm currently using mongoid (mongomapper isn't as compatible with rails3 yet as I would like), and comments are an embedded resource (mongoid can't yet handle polymorphic relational resources), which means that I do need the parent resource in order to find the comment. Are there any elegant ways to handle some of the following problems: in my controller, I need to find the parent before finding the comment. if params[:post_id] parent = Post.find(params[:post_id] else if params[:picture_id] parent = Picture.find(params[:picture_id] end which is going to get messy if I start adding more things to be commentable also url_for([comment.parent,comment]) doesn't work, so I'm going to have to define something in my Comment model, but I think I'm also going to need to define an index route in the Comment model as well as potentially an edit and new route definition. There might be more issues that I have to deal with as I get further. I can't imagine I'm the first person to try and solve this problem, are there any solutions out there to make this more manageable?

    Read the article

1 2  | Next Page >