RubyonRails - bigktmbig/MyExperienceAlgorithm GitHub Wiki
- create db:
rake db:create
- migrate db :
rake db:migrate
- duplicate db(test):
rake db:test:prepare
- create new db: config in config/database.yml and file Gemfile(gem 'mysql2').
- create schema all table:
rake db:schema:dump
- create schema table(Posts):
rails g migration create_Posts
then run:rake db:migrate
- create all: controller, model, view, db schema,...:
rails generate scaffold Comment body:text
- create controller only:
rails g controller ControllerName action1 action2 --skip-template-engine
- authenticate available(https://github.com/plataformatec/devise):
gem 'devise'
(add to Gemfile file)rails generate devise:install
rails generate devise User
- root to(routes.rb):
root 'home#index'
rails generate devise:views users
rails generate devise:controllers users
Vagrant cmd:
- start:
vagrant up
- stop:
vagrant halt/resume
- reset VM:
vagrant destroy/reload
rails methods
- Delete a record in Paragraph class belong to Post class:
post.paragraphs.delete(Paragraph.find(paragraph_id))
- Create, add, remove (table, column):
rails generate migrate addColumnABCTable
- display data: in controller(
puts @var_name.inspect
) and in view(variableName.inspect ex:@var_name.inspect
)
bundle
- in instances we can use:
bundle exec lib_name .(wheneverize .)
Cronjob whenever
- install whenever: Gemfile(gem 'whenever', :require => false), cd in app folder(
cd /apps/my-great-project
), run cmd create config/schedule.rb file(bundle exec wheneverize .
). - edit schedule.rb file:
set :environment, "development"
set :output, "#{path}/log/cron_log.log"
every 2.minutes do
command "echo 'Big Came here'"
end
- update crontab file:
whenever --update-crontab
- check list crontab:
crontab -l
- remove all cronjob:
crontab -r
- run server:
rails s