I’ve found the easiest way to manage the config/database.yml file in a Rails + Capistrano configuration is to add the following line to your capistrano config/deploy.rb configuration file: set :linked_files, %w{config/database.yml} Then add config/database.yml to your .gitignore file. After which, add your environment’s database.yml file to the appropriate location on the remote server(s): #{deploy_to}/appname/shared/config/database.yml Where deploy_to is the deploy_to capistrano configuration setting. This way the configuration parameters are not stored [...]
Read More
If you’re running into the following error attempting to deploy via Capistrano with rbenv, foreman, and upstart: -su: bundle: command not found Then, be sure to take the export and eval rbenv statements in your ~/.bashrc file and copy them to the bottom of your ~/.profile export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)"   As this path will not be available to the user to run the necessary commands otherwise.
Read More
In Ruby/Rails, if you’re running into the following error: Net::HTTPBadResponse: wrong status line When attempting to post data to a secure (https) url, with something similar to: Net::HTTP::post_form("https://www.example.com",{})   Then you can rewrite your request to avoid the exception like this: url = URI.parse("https://www.example.com") http = Net::HTTP.new(url.host,url.port) http.use_ssl = true request = Net::HTTP::Post.new(url.path,{}) request = http.request(request)   After which, you can access the request response in the same way as [...]
Read More
To run a rake task within a shell script using a cron job, do the following: First, specify the shell at the top of your .sh script #!/bin/sh   Then, change your directory to your rails application in your .sh script cd /home/user/app/current   Now, you need to manually define your PATH within the script: PATH=/your/paths:/etc/etc   To see your user’s PATH, do the following in your terminal: echo $PATH [...]
Read More
If you’ve recently loaded a new Rails 4 application to Heroku and your assets are missing (css, js, etc) – you’re not alone. Add the following lines to your production.rb (or staging.rb) environment configuration files: config.serve_static_assets = true config.assets.compile = true Then push the changes up to Heroku and you’re good to go.
Read More
Rails 3.x / 4.0 does not handle remote multipart forms natively, so a workaround is needed. To get remote multipart forms working correctly you can use the following steps (quick solution). First: Add the remotipart gem to your GemFile gem 'remotipart', '~> 1.2.1' Then, Update your javascript manifest file (in basic configurations this is usually found in assets/javascript/application.js). Include the following requirement: //= require jquery.remotipart In my case, I’m binding [...]
Read More