[ rake ] migrate database

rake db:create && rake db:migrate && rake db:seed

NOTE : need rakefile, or Rakefile, or rakefile.rb, or Rakefile.rb

List all rake tasks

rake -T

Generating rake tasks

The code will be generated to lib/tasks/

i.e. lib/tasks/app/test.rake

namespace :app do

desc 'whatever'

task :test, [:params1] do |_, args|

puts args[:params1]

puts #{func1(args)}


def func1(args)

return if args[:params1].blank?



rake app::test[50]

rake options : –trace

ref : http://railsguides.net/how-to-generate-rake-task/

, https://edelpero.svbtle.com/everything-you-always-wanted-to-know-about-writing-good-rake-tasks-but-were-afraid-to-ask

bundler : package manager


gem install bundler

or install specific version of bundler

gem install bundler -v 1.11.2




  • need GemFile
  • ‘bundle’ is a shortcut for ‘bundle install’

Gemfile example

source 'https://rubygems.org'
gem 'nokogiri'
gem 'rack', '~> 2.0.1'
gem 'rspec'

Force reinstall

bundle install --force

ref : https://stackoverflow.com/questions/45290135/how-do-i-force-bundler-to-reinstall-all-of-my-gems

Installation log

Bundler and RubyGems.org are free for anyone to use, but maintaining them costs more than $25,000 USD every month. Help us cover those costs so that we can keep the gem ecosystem free for everyone: https://ruby.to/support-bundler</pre>
When upgrading Re-run the migrations generator rake acts_as_taggable_on_engine:install:migrations This will create any new migrations and skip existing ones Version 3.5.0 has a migration for mysql adapter Post-install message from haml: HEADS UP! Haml 4.0 has many improvements, but also has changes that may break your application: * Support for Ruby 1.8.6 dropped * Support for Rails 2 dropped * Sass filter now always outputs tags * Data attributes are now hyphenated, not underscored * html2haml utility moved to the html2haml gem * Textile and Maruku filters moved to the haml-contrib gem For more info see: http://rubydoc.info/github/haml/haml/file/CHANGELOG.md Post-install message from httparty: When you HTTParty, you must party hard! Post-install message from compass: Compass is charityware. If you love it, please donate on our behalf at http://umdf.org/compass Thanks! Post-install message from money: Please note the following API changes in Money version 6 - Money#amount, Money#dollars methods now return instances of BigDecimal (rather than Float). Please read the migration notes at https://github.com/RubyMoney/money#migration-notes and choose the migration that best suits your application. Test responsibly 🙂 Post-install message from rails_best_practices: ******************************************************************************** rails_best_practices is a code metric tool to check the quality of rails codes. I highly recommend you browse the Rails Best Practices website first. http://rails-bestpractices.com Please also try our online service http://railsbp.com Enjoy! Richard Huang (flyerhzm@gmail.com) ******************************************************************************** Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: = 1.9.2 : nothing to do! Yay!

Gemfile example

Example of Gemfile generated from rails.

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'

group :development do
# Access an IRB console on exception pages or by using  in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'

NOTE : gem server : `​https://rubygems.org` by default

If some of your gems need to be fetched from a private gem server, this default source can be overridden for those gems.

After installing any needed gems to your system, bundler writes a snapshot of all of the gems and versions that it installed to Gemfile.lock.

Gem with Git dependency

gem 'twitter', git: 'https://github.com/sferik/twitter.git'
gem 'twitter', git: 'https://github.com/sferik/twitter.git', branch: 'master'

ref : http://bundler.io/v1.7/rationale.html#checking-your-code-into-version-control,


[ homebrew ] MacOS package manager

brew install &lt;application name&gt;

application example










NOTE : to secure it run


to connect

mysql -uroot

start mysql and restart at login

brew services start mysql


launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

run mysql, without background service

mysql.server start


Please note by default only English locale support is provided. If you need
full locale support you should either rebuild with full icu:
`brew reinstall node –with-full-icu`
or add full icu data at runtime following:

Bash completion has been installed to:


Add the following lines to your ~/.bash_profile:

[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

Bash completion has been installed to:


adding to ~/.bash_profile

source /usr/local/git/contrib/completion/git-completion.bash

[ mongodb ] find array of hash


use $elemMatch

long answer


{"x" :
{ "y":
{"key": "prXXXXX",
"count": 1},
{"key": "pr12345",
"count": 2}


db.collectionA.find({ "x.y.z.m": {$elemMatch: { "key":"prXXXXX", "count": {$gt:1} } } })


ref : http://www.w3resource.com/mongodb/mongodb-elemmatch-operators.php