Consumer ID without rails

Source: Internet
Author: User
Tags configuration settings


I'm playing with a standalone Ruby application and can't configure your ID 3.0.13 to work.

I 've run startup ss a couple example apps that have configuration blocks like:

Mongoid::Config.instance.from_hash({"database" => "oid"})


Mongoid.configure do |config| name = "mongoid_test_db" host = "localhost" port = 27017 config.database =

These result in:

undefined method `database=‘ for Mongoid::Config:Module (NoMethodError)

It seems the configuration settings have changed recently.

I also tried:


But that seems to do nothing.


By "standalone" I'm assuming you mean not rails. Please ID actually provides and easy to make this work regardless of what you're re running it in.

  1. Definemongoid.ymlFile with your database connection info in it like normal.
  2. Make sure you 've required upload ID in your application.
  3. CallMongoid.load!To have upload ID parse your configuration file and initialize itself.

    Require 'regionid'
    Upload ID. Load! ('/Path/to/Your/your ID. yml ')

This info can also be found here under the "Sinatra, Padrino, and others" section:

The same approach is applicable for non-webapps. Hope that helps.


The previous answer is correct to use your ID. Load! If you want to load from a consumer ID config file. I ran into a case where I needed to embed the specified ID config in another config file. therefore, I needed a way to load the configuration from a hash.

In> 3.1, you will be able to call your ID. load_configuration (hash ).

Unfortunately, this function is private in 3.0. Therefore, setting up a public alias method before loading consumer id works:

module Mongoid  module Config    def load_configuration_hash(settings)      load_configuration(settings)    end  endend

Make sure this code gets called before require 'upload id'. Now you can call your ID. load_configuration_hash (hash ).



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.