Generating Entity-Relationship Diagram for Ruby on Rails

Installation
Install graphviz (if not yet)
window http://www.graphviz.org/Download_windows.php
linux sudo apt-get install graphviz
osx brew install graphviz

Add the gem

In the project gemfile add

group :development do
  gem 'rails-erd'
end


Then execute cd PATH_OF_THE_PROJECT && bundle install

Using it
It's as simple as a bundle exec rake erd and it will generate a PDF file in the root of the app.

Rails 4.1.0 - Nginx Bad Gateway with Passenger

I'm writing a little issue tracking application, and as it's a new app I'm using the new shiny Rails 4.1.0. However, whilst the application runs fine locally using Webrick I've been unable to get it working when deployed onto a live (staging) environment running Passenger and Nginx (using the Ubuntu package available via the Phusion Passenger site).

When deployed and configured, Nginx reports a 502 Bad Gateway exception. Digging throught the Nginx error log (in /var/log/nginx), the error becomes clear:

Exception RuntimeError in Rack application object (Missing secret_key_base for 'production' environment, set this value in config/secrets.yml)

Opening secrets.yml shows that there is no value for production:

development:
  secret_key_base: **not_for_prying_eyes**

test:
  secret_key_base: **not_for_prying_eyes**

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>


You can either set an environment variable, or directly configure a value here (you can run rake secret to generate a key). Just make sure that if you do the latter, you've added secrets/yml to your .gitignore!

bundle install --deployment

หาก Gemfile ใช้ gem ที่ยังไม่ใช่ .gem เช่น

   

gem 'prawn', git: 'https://github.com/prawnpdf/prawn', branch: 'master'


*** อย่าลืมลง git ด้วย ถ้า source เป็น git

   
http://code.google.com/p/msysgit/downloads/list


bundle install ก็ผ่านปกติ แต่...

   
Error message:
        https://github.com/prawnpdf/prawn (at master) is not checked out. Please run `bundle install` (Bundler::GitError)


แก้ไขด้วย

   
bundle install --deployment


RAILS MySQL ssh Tunnel

มีโทรศัพท์แจ้งมาว่า "แบท พี่เปลี่ยนวิธี connect mysql ให้ต้อง ssh tunnel นะ"
ตึ่งโป๊ะ!!! ทำไงๆๆๆ คืออะไร แค่เคยเห็นผ่านๆ แล้ว Ruby on Rails ทำไง

อันดับแรก
ssh -N -L 8888:127.0.0.1:3306 -f remote-user@remote-domain-or-ip

ใน database.yml ก็

 production:
  adapter: mysql2
  encoding: utf8
  host: 127.0.0.1
  port: 8888
  database: databasename
  username: remote-user
  password: password-remote-user


เสร็จ connect สำเร็จ ข้อมูลมา แต่ทำไมออกมาไม่เหมือนกัน
อ้าว!!! เปลี่ยนชื่อ database อีกก็ไม่บอก

Send backup by email with crontab


echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com


So probably the approach to follow will be something like,

tar -zcf /home/blah/backup.tgz /home/blah/
echo "Please find attached the backup file" | mutt -a "/home/blah/backup.tgz" -s "File attached" -- recipient@domain.com


I will save the above script as backup_email.sh and schedule the cron job as,

0 1 * * * /path/to/backup_email.sh