Posts

Showing posts from 2016

Insert Bulk data using active record import

Imagine a scenario where you have to create a report and send it to multiple clients, so lets just say you have a report model and you have client and you have report client model. lets first check all the association and model structure. #report model class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients end #report_client class ReportClient < ActiveRecord::Base   belongs_to :report   belongs_to :client end #clients class Client < ActiveRecord::Base   has_many :report_clients   has_many :reports, through: :report_clients end No lets say you want to create a report for 30 clients. You can do that by adding nested attributes in rails. so our report model will became  class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients   accepts_nested_attributes_for :report_clients, :reject_if => proc { |attributes| att

Insert Bulk data using active record import

Imagine a scenario where you have to create a report and send it to multiple clients, so lets just say you have a report model and you have client and you have report client model. lets first check all the association and model structure. #report model class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients end #report_client class ReportClient < ActiveRecord::Base   belongs_to :report   belongs_to :client end #clients class Client < ActiveRecord::Base   has_many :report_clients   has_many :reports, through: :report_clients end No lets say you want to create a report for 30 clients. You can do that by adding nested attributes in rails. so our report model will became  class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients   accepts_nested_attributes_for :report_clients, :reject_if => proc { |attributes| att

Postgres database is not running after OSX crash

Every one might have face the problem that Postgres id not running after OSX is crashed. Every time you try to start the Postgres server it will say : - another server might be running; trying to start server anyway You can follow the below steps to get rid of the problem. Step 1: Open your terminal and run   pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start   It will Say   pg_ctl: another server might be running; trying to start server anyway Step 2:  Check the log $ tail -f /usr/local/var/postgres/server.log It will print something like this FATAL:  lock file "postmaster.pid" already exists HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"? FATAL:  lock file "postmaster.pid" already exists HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"? Step 3: Delete the PID file. $ rm /usr/local/var/postgres/postmaster.pid S