Posts

Redirect non www to www via routes.rb in rails

In routes.rb: if Rails.env.production?     def query_params_to_query(request)       query_params = request.params.except(:path, :format, :subdomain)       query_params.any? ? "?#{query_params.to_query}" : ""     end       constraints(:subdomain => '') do       redirect_action = ->(params, _request) do         "https://www.example.com/#{params[:path]}#{query_params_to_query(_request)}"       end       root to: redirect(redirect_action)       get '/*path', to: redirect(redirect_action)     end   end

Copy files or folder from local to AWS s3 bucket

Import S3tools signing key:     wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add -  A dd the repo to sources.list:    sudo wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list R efresh package cache and install the newest s3cmd:  sudo apt-get update && sudo apt-get install s3cmd   s3cmd --configure New settings: 2 Access Key: [your access key] 3 Secret Key: [your securet key] 4 Encryption password: somepassword 5 Path to GPG program: /usr/bin/gpg 6 Use HTTPS protocol: False 7 HTTP Proxy server name: 8 HTTP Proxy server port: 0 9 Test access with supplied credentials? [Y/n] Y 10 Please wait... 11 Success. Your access key and secret key worked fine :-) 12 13 Now verifying that encryption works... 14 Success. Encryption and decryption worked fine :-) 15 Save settings? [y/N] y Run Command To transfer file from source to   ============================== ============= s3cmd sync uploads s3://b

Import database direct from heroku into ruby on rails applpication

heroku pg:backups:capture --app yourappname Hit Ctrl-C at any time to stop watching progress; the backup will continue running. Stop a running backup with heroku pg:backups:cancel. HEROKU_POSTGRESQL_BLACK (DATABASE_URL) ----backup---> b251 Running... done heroku pg:backups:restore b251 DATABASE_URL --app yourappname

Clear cache on heroku

heroku run --app YOUR_APP_NAME rails runner Rails.cache.clear If the above does not work, try running: heroku run rake tmp:create heroku run rake tmp:clear

Convert databases from SQLite to PostgreSQL

gem install sequel sequel - C sqlite : //db/development.sqlite3 postgres://user:password@localhost/dbname

Deploy Ruby On Rails application on production AWS Ec2 server

1. Give 400 permission to pem file. sudo chmod 400 example.pem 2. Login on server.  ssh -i  example. pem file ubuntu@ip_address ------------------------------ ------------------------------ ---------- 3. You can check ubuntu server details by: lsb_release -a No LSB modules are available. Distributor ID:    Ubuntu Description:    Ubuntu 16.04.2 LTS Release:    16.04 Codename:    xenial ------------------------------ ------------------------------ ---------- 4. Install the required libraries: sudo apt-get update sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs yarn sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev gpg --keyserver hkp:// keys.gnupg.net  --recv-keys 409B6B1796C275462A1703113804BB 82D39DC0E3 curl -sSL  https://get.rvm.io  | bash -s stable source