Friday, October 23, 2015

authorize! for update

just realize calling model.update after authorize! is wrong!

the right way is to run an authorize!, then model.assign_attributes, then rerun authorize! again, 
and finally

Tuesday, October 20, 2015

running rvm based cron job

rvm is requires a bash login to work.
in order to execute cron jobs, run this:

*/5 * * * * 'sh /home/myuser/versions/current/'

create a shell file,
change working directory to rails root,
and run the required job, such as delayed_job once and exit

vi /home/myuser/versions/current/
cd /home/myuser/versions/current
/bin/bash -l -c 'RAILS_ENV=production bundle exec rake jobs:workoff'

Thursday, October 1, 2015

speeding up vagrant and virtualbox synced folder on mac and windows

first, use nfs for sync folder,

in Vagrantfile:
web.vm.synced_folder "/private/var/www", "/var/www", type: "nfs", mount_options: ['rw', 'vers=3', 'tcp', 'fsc', 'actimeo=2']

actimeo=2 # increases speed of file sync

then do a: 
vagrant reload

On Windows:
web.vm.synced_folder "c:/wamp/www", "/var/www", type: "smb"

Notes: nfs on windows is not fully compatible. On linux guest machine, it does not allow file locking. This isn't good enough with rails, especially. Smb is an good option with file locking support, and fast response time. But this requires running command prompt as administrator to start smb command.

Hope it helps ;)