Some tips for ruby on rails

#rollback a specific MIGRATION
bundle exec rake db:migrate:down VERSION=20170713152322
bundle exec rake db:migrate VERSION=20170713152322

#Add remove index in rails migration
add_index :fcm_messagings, [:user_id], :unique => true
remove_index “fcm_messagings”, name:’index_fcm_messagings_on_user_id’

#exception handling
begin
@request.send_fcm_notification_accept_communication_request
rescue => ex
logger.error ex.message
end

#deploy ruby on rails on vps
http://geekhmer.github.io/blog/2016/07/13/setup-and-deploy-ruby-on-rails-on-ubuntu-16-dot-04-or-latest/

and add
sudo apt-get install nodejs

#rails debug not working
add in gem file
group :development, :test do
gem ‘rspec-rails’, ‘~> 3.0’
gem ‘factory_girl_rails’
gem ‘cucumber-rails’, require: false
gem ‘simplecov’
gem ‘simplecov-rcov’
gem ‘capistrano-rails’
gem ‘capistrano’
gem ‘capistrano-rvm’
gem ‘capistrano-bundler’, ‘~> 1.1’
gem ‘letter_opener’
gem ‘bullet’
gem ‘launchy’
gem ‘rubocop’
gem ‘ruby-debug-ide’
gem ‘debase’
end

#Rubymine Desktop entry
[Desktop Entry] Version=1
Name=Rubymine
Comment=My desktop entry
Exec=/opt/RubyMine-2017.1.3/bin/rubymine.sh
Icon=/opt/RubyMine-2017.1.3/bin/rubymine.png
Terminal=false
Type=Application
Categories=Utility;Application;

#rails 4
collection.present? or collection.blank? to check there is a value in a collection or not

#route
Delete public.html
Add in the last line in routes.rb

root :to => “topics#index”

to routes.rb
and then of course create the controller foo with the action index.

#see all the routes
http://localhost:3000/rails/info/routes

#console
bundle update rake

#all rake command in rails
bundle exec rails routes

#migration
#redo a specific migration in rails
bundle exec rake db:migrate:redo VERSION=20170615091326

Leave a Reply

Your email address will not be published. Required fields are marked *