Skip to content

Instantly share code, notes, and snippets.

@jagdeepsingh
Created May 3, 2021 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagdeepsingh/acd14fdfa822866b61a157b084c19c6b to your computer and use it in GitHub Desktop.
Save jagdeepsingh/acd14fdfa822866b61a157b084c19c6b to your computer and use it in GitHub Desktop.
Setup new Rails 6.x application using Mongoid 7.x

Mongoid

Title Link
Github https://github.com/mongodb/mongoid
Docs https://docs.mongodb.com/mongoid/current/

1 New Rails Application

Make sure you have ruby installed. I am using rbenv to maintain different versions of ruby across projects.

% rbenv -v
rbenv 1.1.2

% ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]

1.1 Install rails

% gem install rails -v '~> 6.0.0'

% rails -v
Rails 6.0.3.6

1.2 Create application

% rails new blog --skip-active-record --skip-bundle

% cd blog

Note: You may receive a warning like this:

Could not find gem 'puma (~> 4.1)' in any of the gem sources listed in your Gemfile. Run bundle install to install missing gems.

Disregard it as we will be taking care of gem installation in a moment.

Add following to the Gemfile:

gem 'mongoid', '~> 7.0.5'

Install gem depndencies.

% bundle install

Generate the default Mongoid configuration.

% bin/rails g mongoid:config

Install yarn.

% npm -v
6.14.4

% npm install --global yarn

Install webpacker.

% rails webpacker:install

(Optional) Push your code to a Github repository

Create an empty repository named blog on github.com.

% git init .
% git add .
% git commit -m 'Initial commit'
% git remote add origin git@github.com:jagdeepsingh/blog.git
% git branch -M main
% git push -u origin main

Make sure a MongoDB server is running locally.

Run application.

% rails s

Your application is now running on http://127.0.0.1:3000.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment