Store data retrieved as result of find_by_sql method in ruby on rails -


i new ruby on rails. trying retrieve data database , make operation in rails application. stuck while trying use find_by_sql in class activity < activerecord::base

i have rates table structure

id | instrument name | category | time_of_usage | rates 1  | instrument1     | internal | regular       | 25 2  | instrument2     | internal | weekends      | 15   

here sample code of trying achieve

sql2='select rates new_billcodes_mock category_name=?, instrument_name=? , time_zone_name=?' result2=  find_by_sql[sql2,'internal','instrument1',time_zone_name] database_billrate_value_normal=result2['rates'] 

and use database_billrate_value_normal variable make operations.

please guide me in correct path if wrong.

i'm unclear if model rate table activity or newbillcodemock or rate.

if rate, should able this:

database_billrate_value_normal =      rate.where("category_name=? ,                  instrument_name=? ,                  time_zone_name=?",                 params[:category_name],                 params[:instrument_name],                 params[:time_zone_name]).pluck[:rates] 

... assuming have hash params required attribute values actual attribute names.

this return array of rates can manipulate directly in ruby needed.


Comments