Rails console is not outputting SQL Statements to my Development Log

the rails console never writes to the log file, but you can achieve it quite easily, for example, if you execute following after starting the rails console ActiveRecord::Base.logger = Logger.new STDOUT rails will log all SQL statements to stdout, thus display them in your terminal. and since Logger.new accepts any stream as first argument, you … Read more

How to calculate the distance between two GPS coordinates without using Google Maps API?

Distance between two coordinates on earth is usually calculated using Haversine formula. This formula takes into consideration earth shape and radius. This is the code I use to calculate distance in meters. def distance(loc1, loc2) rad_per_deg = Math::PI/180 # PI / 180 rkm = 6371 # Earth radius in kilometers rm = rkm * 1000 … Read more

Changing type of ActiveRecord Class in Rails with Single Table Inheritance

Steve’s answer works but since the instance is of class BaseUser when save is called, validations and callbacks defined in User will not run. You’ll probably want to convert the instance using the becomes method: user = BaseUser.where(email: “[email protected]”).first_or_initialize user = user.becomes(User) # convert to instance from BaseUser to User user.type = “User” user.save!

rails best practices where to place unobtrusive javascript

I do not think there is one best practice, but I’ll let you know what I do. I have a series of js files each for with their own purpose in the public/javascripts/ directory. Some examples could be utility.js chat.js shopping_basket.js and so on. I use asset packager and define one big fat collection for … Read more

Calling Python from Ruby

This article gives some techniques for running Ruby code from Python which should also be applicable in the reverse direction (such as XML-RPC or pipes) as well as specific techniques for running Python code from Ruby. In particular rubypython or Ruby/Python look like they may do what you want.

What is the argument against using before, let and subject in RSpec tests? [closed]

Interesting question; something that I want to know more about as well…. So dug in a bit, and here is what I uncovered: Thoughtbot style guide dictum about let, etc. In an earlier version of the style guide, there’s more to that statement: Avoid its, let, let!, specify, subject, and other DSLs. Prefer explicitness and … Read more