Thursday 27 August 2020

Generate Dynamic File with Content in rails

 EmailTemplate.where("locale = 'de'").each do |et|

 body = et.body

 File.open("templates/#{et.slug}.html", 'w+') {|f| f.write(body) }

end

Tuesday 18 August 2020

set root password in mysql for root user

 ~$ sudo mysql

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

mysql> exit

$ mysql -u root -p

$ Enter Password: root

Tuesday 4 August 2020

Avoid N+1 Queries

1 . Location.includes(:users).where(users: {username: "ashish"}) 
Lead.includes(:contacts).where("contacts.primary" =>true)

2. Person.includes(notes: [:grades]).where(notes: {important: true, grades: {important: true})

3. 
  class Person < ActiveRecord::Base
has_many :notes
has_many :important_notes, -> { where(important: true) }, class_name: "Note"
end

Person.preload(:important_notes)
4. Person.eager_load(:notes)

Revert last commit or second last and more....

 Git revert commit_id -m 1 this command willl revert last commit  Git revert commit_id -m 2 this command will revert second commit with same...