Advantage of using find_each and find_in_batches in rails

Usually when we want to loop through all rows of an active record model, we do User.all.each  { |user| user.update_role  } But when we do this in Rails console, it loads all the User objects in to memory and performs the action. Performance of the application will go down if number of users is more. To […]

Read more "Advantage of using find_each and find_in_batches in rails"

How to show Google Analytics dashboard in a Ruby on Rails application?

I was researching on importing GA dashboard in my rails application. Putting together steps involved in it and the reference links here 1. Understand Google Analytics dimensions and metrics Reference Links Google Analytics metrics and dimensions Difference between dimensions and metrics Google Spreadsheet which has list of dimensions and metrics GA API tool – This […]

Read more "How to show Google Analytics dashboard in a Ruby on Rails application?"

splat operator in Ruby

Arraying your arguments The list of parameters passed to an object is, in fact, available as a list. To do this, we use what is called the splat operator – which is just an asterisk (*). The splat operator is used to handle methods which have a variable parameter list. Let’s use it to create […]

Read more "splat operator in Ruby"

Mysql self left join

I have the following employee table Emp ID Month Salary 1000 Aug 35000 1001 Aug 45000 1002 Aug 60000 1000 Sep 37000 1001 Sep 46000 Query to fetch the salary details of employees for August and September month in a single row   select e1.emp_id,e1.salary as august_month_salary,e2.salary as september_month_salary from employees e1 left join (select […]

Read more "Mysql self left join"