Posts

#14. Rails notes command

 raj@linux:~/workspace/test_app$ rails notes -h Usage:   rails notes [options] Options:   -a, [--annotations=one two three]  # Filter by specific annotations, e.g. Foobar TODO Example, raj@linux:~/workspace/test_app$ rails notes -a DEBUG app/controllers/configs_controller.rb:   * [6] This is not exactly working raj@linux:~/workspace/test_app$ rails notes -a DEBUG TEST TODO app/controllers/application_controller.rb:   * [5] [TODO] Check this method for optimization app/controllers/configs_controller.rb:   * [6] [DEBUG] This is not exactly working app/controllers/feedbacks_controller.rb:   * [2] [TEST] Have to write test cases for this method raj@linux:~/workspace/test_app$ rails notes app/controllers/application_controller.rb:   * [5] [TODO] Check this method for optimization

#12. Memcache

Uninstallation/Installation, sudo apt-get remove memcached sudo apt-get remove --auto-remove memcached sudo apt update && sudo apt upgrade sudo apt install memcached  # For the use of mem-cache gem 'dalli' root@test_app:~# memcached -h | head -1 memcached 1.5.22 rails dev:cache root@test_app:~# ls tmp/ cache  data  development_secret.txt  miniprofiler  pids  res  restart.txt  sockets root@test_app:~# rails dev:cache Development mode is now being cached. root@test_app:~# ls tmp/ cache  caching-dev.txt data  development_secret.txt  miniprofiler  pids  res  restart.txt  sockets root@test_app:~# rails dev:cache Development mode is no longer being cached. root@test_app:~# ls tmp/ cache  data  development_secret.txt  miniprofiler  pids  res  restart.txt  sockets touch tmp/restart.txt root@test_app:~# ls tmp/ cache  caching-dev.txt data  development_secret.txt ...

#10. positive? method

 3.0.4 :001 > 0.positive?  => false  3.0.4 :002 > 1.positive?  => true  3.0.4 :003 > -1.positive?  => false

#8. nginx+puma deployment using capistrano

 In the Gemfile, ---------------------------------------- group :development do   gem 'capistrano',         require: false   gem 'capistrano-rvm',     require: false   gem 'capistrano-rails',   require: false   gem 'capistrano-bundler', require: false   gem 'capistrano3-puma',   require: false end -------------------------------------------------- bundle install cap install create a file as,  /home/raj/workspace/chat/config/nginx.conf ------------------------------------------------ upstream puma {   server unix:///home/raj/deployed_apps/chat/shared/tmp/sockets/chat-puma.sock; } server {   listen 80 default_server deferred;   # server_name example.com;   root /home/raj/deployed_apps/chat/current/public;   access_log /home/raj/deployed_apps/chat/current/log/nginx.access.log;   error_log /home/raj/deployed_apps/chat/current/log/nginx.error.log info;   location ...

#11. Run rails app in production mode

Check in produciton.rb, it should be false, config.assets.compile = false  precompile the assets, RAILS_ENV=production bundle exec rake assets:precompile It should be set in the env file as true config.public_file_server.enabled = true Then run server as, rails s -e production or RAILS_ENV=production rails s

#13. docker helpful commands

Restarting docker -   service docker restart docker images -a docker rmi Image Image

#6. Fetch time in rails

 In the Rails do not prefer to use Time.now, Date.today etc We should always prefer to use it with zone like, Time.zone.now, Time.zone.today etc. but why so? Beacause when we fetch Time.now its always return system local time and ignore  config.time_zone  set in the  application.rb. file. Here is the example tested in the rails console, 3.0.3 :001 > Time.now  => 2022-04-19 09:57:58.413034249 +0530  3.0.3 :002 > Time.zone  => #<ActiveSupport::TimeZone:0x000055704feec360 @name="UTC", @tzinfo=#<TZInfo::DataTimezone: Etc/UTC>, @utc_offset=nil>  3.0.3 :003 > Time.zone.now  => Tue, 19 Apr 2022 04:28:07.277000358 UTC +00:00  3.0.3 :004 > Time.zone = 'Sydney'  => "Sydney"  3.0.3 :005 > Time.zone  => #<ActiveSupport::TimeZone:0x000055705192d850 @name="Sydney", @tzinfo=#<TZInfo::DataTimezone: Australia/Sydney>, @utc_offset=nil>  3.0.3 :008 > Time.now  => 2022...