You do not need and do not need attr_accessor . attr_accessor creates an instance variable, an access method to get the value of this instance variable, and a mutator method to change its value. When you say this:
select('gateways.*, (num_transactions_today/ SUM(num_transactions_today)) AS percentage_used ...
ActiveRecord will automatically add the percentage_used method to the returned objects. But the percentage_used method to access this value will be added method_missing . Since you said attr_accessor :percentage_used , method_missing will never be called, and you cannot get the value of percentage_used from the request in the usual way.
If you release attr_accessor :percentage_used , you can call percentage_used on the objects returned by this select , and you will find the values you need. However, AR will not be able to convert the value to its own Ruby number, so you will have to_f return the string yourself.
source share