Whenever : Cron tab : Environment selection

For whenever gem Default Rails environment is production. However, you sometime would like to set environment manually for testing purposes.

If you try

$ whenever -h
Usage: whenever [options]
 -s, --set [variables] Example: --set 'environment=staging&path=/my/sweet/path'

if you need to set environment to development then try this

$ whenever --update-crontab --set 'environment=development'

 

# In schedule.rb
# run this task only on servers with the :app role in Capistrano
# see Capistrano roles section below

# variable `environment` is accessible here; you set from CLI
set :whenever_environment, environment || 'production'

every :day, :at => '12:20am', :roles => [:app] do 
  rake "app_server:task" 
end

You can list installed cron jobs using crontab -l.

 

jQuery DataTables: Update a row / cell after any event without table or page reload

Updating a cell or a whole without reloading the page of the table itself using AJAX is not that hard. However, in lack of proper documentation or tutorials or examples users find difficult to implement this. Continue reading

Ruby On Rails : ActiveRecord : Batch update/create : Updating/Creating Multiple records at the same time

Sometime you may require to update multiple rows in your tables with different data. If you were looking for updating all record with same data then you should go for update_all method.

Batch update

 # Updating multiple records; different col with different data:
  people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }
  Person.update(people.keys, people.values)

Continue reading