Posts

#23. RoR commands

Remove  master.key and credentials.yml.enc then run following command to regenerate it, EDITOR="vim --wait" rails credentials:edit cat /etc/apt/sources.list.d/pgadmin4.list If you have UFW firewall configured, allow http and https traffic. sudo ufw allow http sudo ufw allow https For taking dump, psql -U your_user_name -h your_remote_ip -p 5432 -d your_db_name -f Path_for_db_dump_file bundle exec rake jobs:work Start queue, RAILS_ENV=development bin/delayed_job --queues=queue_name1,queue_name2,queue_name3 start​​ Stop queue, RAILS_ENV=development bin/delayed_job --queues=queue_name1,queue_name2,queue_name3 stop rvm gemset create your_gemset_name which rvm gemset location /home/{​​​​​​​​{​​​​​​​​user}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​/.rvm/gems like,  /home/raj/.rvm/gems rvm gemset list rvm use ruby-3.0.0@your_gemset_name rvm -- rvmrc ruby-3.0.0@your_gemset_name Editor I used - Rubymine/Sublime/VisualCode rvm gemdir gem li...

#22. Getting started with an existing Rails project

Start with following, routes  rake routes readme schema *_id search - for association project structure models lib/* controllers views rails test cases Use rails debuggers tool like pry Use browser dev tools see the flow with logs

#21. Rails scope

Author has_many books books belongs_to author Named Scope scope :available, -> { where(available: true) } select 'books'.* from books where books.available = 't' scope :unavailable, -> { where(available: [nil, false]) } select 'books'.* from books where books.available = 'f' or books.available is null scope :public_status, -> { where(status:  'public') } 3.1.2 :004 > Article.public_status   Article Load (0.2ms)  SELECT "articles".* FROM "articles" WHERE "articles"."status" = ? AND "articles"."status" = ?  [["status", "public"], ["status", "public"]] Here two times same status(‘public’) checked because one of the default scope and one of the named scope( public_status ). Author.joins(:books).merge(Book.available) select authors.* from authors inner join books on books.author_id=authors.id where books.available = 't' We can achi...

#20. List of things a RoR developer should be aware about

Environment variables Ruby Version Manager - RVM, rbenv gemset, bundler Rails App Structure rackup file - config.ru params - paraqmeters in rails query parameters Why http://localhost:3000/users/1 and not http://localhost:3000/users?id=1 Restful API Agile methodlologies MVC design patterns Why just instance variables pass from controller to view active record rails scope - named, default, unscope

#19. MySQL date time related query

 select CONVERT_TZ(now(), '+00:00', '+05:30') as converted_datetime; # converted_datetime '2022-07-06 19:28:31' select now() as current_dt; # current_dt '2022-07-06 13:56:07' select CURDATE() as current_dt; # current_dt '2022-07-06' SELECT @@global.time_zone, @@session.time_zone; # @@global.time_zone, @@session.time_zone 'SYSTEM', 'SYSTEM' select timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00')); # timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00')) '10:00:00' select convert_tz(now(),@@session.time_zone,'+00:00'); # convert_tz(now(),@@session.time_zone,'+00:00') '2022-07-06 04:03:47' select @@session.time_zone; # @@session.time_zone 'SYSTEM' SELECT @@system_time_zone; # @@system_time_zone 'AEST' SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP); # TIMEDIFF(NOW(), UTC_TIMESTAMP) '10:00:00' select UTC_TIMESTAMP; # UTC_TIMESTAMP '2022-07-06 04:07:...

#18. Ruby on Rails usefull commands

 gem install rails rails new hrms -d postgresql

#17. RVM useful commands

 rvm get head - update rvm rvm install ruby - install latest version of ruby rvm list known - list all known version of Ruby rvm list  - list all installed version of ruby rvm install ruby-3.2  - install ruby version 3.2 rvm --default use ruby-3.2.0-preview1 - set default version for ruby