user3166642 user3166642 - 1 year ago 100
Ruby Question

Converting an ActiveRecord:Relation to java array

I am running a 'where' query which is running on a table MyTable in my rails application.
I want to convert the results of a specific column from this query(ActiveRecord::Relation) to Java Array of String type.

This is what I am doing :

employeesJavaArray=MyTable.where("salary = ?",100).pluck(:columnName).to_java(java.lang.String)

However I am receiving this error in my logs :-

TypeError (could not coerce Fixnum to class java.lang.String):

Can you please help me out what could be wrong with the statement that I have written.

Answer Source

I would ensure that the array only includes string (by calling to_s) first:

employeesJavaArray = MyTable.where("salary = ?",100)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download