MySql with MongoDB in Rails

This is an area I’ve studied a lot lately, because I have an interest in using NoSQL instead of SQL databases for some of my models. Since we’re on Rails 5 and Mongoid 6 now, I just thought I’d share these steps for setting it up now:

1) Create your Rails app with the ‘–skip-active-record’ switch.

2) Remove sqlite3 from your Gemfile, add Mongoid to your Gemfile, and run ‘bundle’.

3) Run ‘rails g mongoid:config’.

4) Check your ‘application.rb’ file and make sure that inside the ‘class Application’ there is the line ” Mongoid.load! ‘./config/mongoid.yml’ “. It’s sometimes not included when the config is generated, but it’s needed to use Mongoid.

5) Mongoid is ready to go. The Rails generators for ‘model’, ‘scaffold’ etc have been overridden by Mongoid. Any models, scaffolds etc that you create will create classes that include the Mongoid::Document module instead of inheriting from ApplicationRecord in the models folder.

—–

And something I’ve also found useful is using both ActiveRecord and Mongoid. MongoDB works great for some types of data, but sometimes I still feel more comfortable with SQL for some data, especially if I feel the need to wrap it in transactions.

1) Create your Rails app.

2) Add Mongoid to your Gemfile and run ‘bundle’.

3) Run ‘rails g mongoid:config’.

4) Check your ‘application.rb’ file and make sure that inside the ‘class Application’ there is the line ” Mongoid.load! ‘./config/mongoid.yml’ “. It’s sometimes not included when the config is generated, but it’s needed to use Mongoid.

5) Mongoid is ready to go. The Rails generators for ‘model’, ‘scaffold’ etc have been overridden by Mongoid. Any models, scaffolds etc that you create will create
classes that include the Mongoid::Document module instead of inheriting
from ApplicationRecord in the models folder.

6) The ActiveRecord generators are still available, you just need to specify to use the ‘active_record’ versions as you use them. For example, at this point ‘rails g model user email’ generates a Mongoid model but ‘rails g active_record:model user email’ generates an ActiveRecord model and creates the needed migration. If you chose to make this a Mongoid model, there is no migration to worry about. If you chose to make this an ActiveRecord model, run the migration with ‘rails db:migrate’. (Rails 5 moved rake functionality into the rails command)

7) You can create associations between ActiveRecord and Mongoid models by manually coding methods. You’ll need to consider foreign keys. For example, if an ActiveRecord User has many Mongoid Posts, you’d add a foreign key field to the Post model. Its type would be Integer since ActiveRecord models use the Integer type for their id. Keep in mind that queries made from these associations can be slower because they traverse two data stores. Take things like lazy loading and the n+1 problem into consideration.

Reference: https://gorails.com/guides/setting-up-rails-4-with-mongodb-and-mongoid

Advertisements

React Native

Install npm and node first

Grant permissions to npm

sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/lib/node_modules/
sudo chown -R $(whoami) /usr/bin/node
sudo chown -R $(whoami) /usr/bin/npm

 

RVM – Gemsets

Creating gemsets

Gemsets must be created before being used. To create a new gemset for the current ruby, do this:
rvm 2.1.1
rvm gemset create teddy
Gemset 'teddy' created.

Alternatively, if you prefer the shorthand syntax offered by rvm use, employ the –create option like so:
rvm use 2.1.1@teddy --create

Select gemsets according to the Project

There is a new way to do this, without having to allow arbitrary shell script to be executed in a .rvmrc file.

Create a file named .ruby-gemset containing only the gemset name in.
multilingo_cms
Need an up to date version of rvm for this to work.

You can also specify the ruby version by creating a file named .ruby-version containing only the ruby version:
1.9.3


This format also has the advantage of being compatible with rbenv and rbfu.

If you have existing projects using the deprecated .rvmrc, you can convert them to the new format using the command:
rvm rvmrc to .ruby-version

RubyMine Ubuntu

rubymine-ide-banner

Install RubyMine

  1. Download RubyMine from Source
  2. Unpack the downloaded archive:
    1. tar -xzf RubyMine-X.Y.Z.tar.gz
  3. Goto extracted folder, nevigate to ‘bin’ directory
    1. ./rubymine.sh
  4. Open any project, goto (Tools) -> (Create Desktop Entry)

Change Rubymine Theme

  1. File -> Settings -> Appearance and Behavior -> Appearance

Remove RubyMine

  1. locate rubymine
  2. locate RubyMine
  3. rm -rf ~/.RubyMine

 

Install Sublime Text 3 Ubuntu

logo_sublimetext_lachicainf

You have to add the PPA to your system, update the local repository index and install the sublime-text-installer:

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

Optional, to remove sublime text, do:
sudo apt-get remove sublime-text-installer

Registration License Key:

—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
B085E65E 2F5F5360 8489D422 FB8FC1AA
93F6323C FD7F7544 3F39C318 D95E6480
FCCC7561 8A4A1741 68FA4223 ADCEDE07
200C25BE DBBC4855 C4CFB774 C5EC138C
0FEC1CEF D9DCECEC D3A5DAD1 01316C36
—— END LICENSE ——

 

Sublime Text 3 Serial key build is 3143

—– BEGIN LICENSE —–
TwitterInc
200 User License
EA7E-890007
1D77F72E 390CDD93 4DCBA022 FAF60790
61AA12C0 A37081C5 D0316412 4584D136
94D7F7D4 95BC8C1C 527DA828 560BB037
D1EDDD8C AE7B379F 50C9D69D B35179EF
2FE898C4 8E4277A8 555CE714 E1FB0E43
D5D52613 C3D12E98 BC49967F 7652EED2
9D2D2E61 67610860 6D338B72 5CF95C69
E36B85CC 84991F19 7575D828 470A92AB
—— END LICENSE ——

Setup Ubuntu Machine

banner-772x250

Install Packages

sudo apt-get install -y curl
sudo apt-get install -y build-essential
sudo apt-get install -y bison byacc gperf
sudo apt-get install -y zlib1g-dev
sudo apt-get install -y libreadline5
sudo apt-get install -y libreadline-dev
sudo apt-get install -y libncurses5 libncurses5-dev
sudo apt-get install -y libssl-dev
sudo apt-get install -y autoconf
sudo apt-get install -y libxml2
sudo apt-get install -y libxml2-dev
sudo apt-get install -y libpng12-0
sudo apt-get install -y libpng12-dev
sudo apt-get install -y libgmp3-dev
sudo apt-get install -y sendmail
sudo apt-get install -y libjpeg62-dev
sudo apt-get install -y openssh-server
sudo apt-get install -y gettext
sudo apt-get install -y imagemagick
sudo apt-get install -y graphicsmagick-libmagick-dev-compat

Install and configure GIT

sudo apt-get install git-core

Colored Git
git config –global color.diff auto
git config –global color.status auto
git config –global color.branch auto
git config –global color.interactive auto
git config –global color.ui true
git config –global push.default tracking
git config –global core.autocrlf false
git config –global core.safecrlf false
git config –global core.ignorecase false
git config –global core.excludefile ~/.gitignore
git config –global diff.renames copies

Install and configure Mysql

sudo apt-get install libmysql++-dev
sudo apt-get install -y mysql-server

Install and configure PHP

sudo apt-get install php

Install PHPMyAdmin

sudo apt-get install phpmyadmin

Install Ruby and Gems

sudo apt-get install ruby
sudo apt install ruby-railties

Install Rvm

curl -L https://get.rvm.io | bash -s stable