Posts

Showing posts with the label ruby on rails

#25 Ruby on Rails application performance and security tools

Security -  rack-attack gem Brakeman gem Performance tools -   bullet rails_best_practice  rubycritic,  rubocop  rack-mini-profiler  spring, memory_profiler  Appsignal(paid) New Relic(paid)  Bullet gem(N+1 query)  rails_best_practice  rubycritic   rubocop brakeman  rack-mini-profiler  spring memory_prof

#24 Some useful gems list

  Purpose gem Debugging Pry Email test Letter Opener Testing rspec simplecov(check test code coverage) Factory_bot rswag faker environment variables figaro/magic-multiconnection tracking visits ahoy Background job sidekiq Search elasticseacrh deployment capistrano-rails Database pg cache redis serialize json data active_model_serializers login devise scheduler(cron job) rufus-scheduler notify exception via email exception_notification push notification ruby-push-notifications Json Web Token (JWT)  for token based authentication RabbitMQ bunny Security https://github.com/Snorby/snorby puma_worker_killer spring magic_multi_connection allocation_stats puma_worker_killer hyper-rails memory_profiler

#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...

#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

#18. Ruby on Rails usefull commands

 gem install rails rails new hrms -d postgresql

#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...

#5. bundle install error

Image
Today I was getting one error as, Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile (LoadError) When I dig it, I found that I run a command previously as,    bundle install --without development test Result of this command, it's saved by default. Refer  here . Now whenever I run  bundle install,  I can see that development and test gems are always ignored like, Here we can see that, development and test environment gems are ignored. In order to solve this error run as, bundle config --delete without After that do bundle install it will install all the gems and that error disappear too.

#1. System setup for Ruby on Rails projects on Ubuntu

Before format take Backup of the following -  Openvpn file - client.openvpn docker file - client certificate file .thunderbird - complete folder .ssh - complete folder .purple - complete folder for pidgin Other Important documents Fresh installation -  Synaptic Package Manager -  Install from software center  sudo apt install vim 'pg' gem supporting libraries sudo apt install libpq-dev sudo apt install libpq-dev build-essential gparted - for memory management Install from software center openvpn - install from software center Pidgin - Install from software center Google chrome - download debian file(.deb) from chrome website git -  sudo apt install git sudo apt install git-gui git alias -  https://learnwithrkumar.blogspot.com/2021/12/create-git-alias.html git global settings -  https://learnwithrkumar.blogspot.com/2021/12/git-setup-on-ubuntu-system.html Ssh key generate and add it to github. sudo apt install net-tools sudo apt install curl postgresql +...

RSpec cheatsheet

RSpec cheatsheet  install rspec-rails gem only, it will install all the rspec related gems. Basic setup steps Step1: gem 'rspec-rails' root@f79191f58a4f:~# gem list rspec *** LOCAL GEMS *** rspec-core (3.9.3) rspec-expectations (3.9.4) rspec-mocks (3.9.1) rspec-rails (3.9.1) rspec-support (3.9.4) Step2: rails generate rspec:install it will create 3 files, .rspec spec/rails_helper.rb spec/spec_helper.rb Step3: put these two lines in the .rspec file, --require spec_helper --format documentation Step4:  run rspec as, rspec ------ Basic knowledge All the spec(specification) files stay inside spec folder. Allthe spec file ends with *_spec.rb Example - spec/sales_spec.rb All files in this directory(spec/**/*_spec.rb)will be run automatically when we run,  rspec Dry run spec as, rspec --dry-run Run a particular spec, rspec spec/sales_spec.rb Run a particular spec from a particular line, rspec spec/coffee_spec.rb:31 Run rspec with formatted output as, rspec --format doc...