I'm using the cassandra gem. http://docs.datastax.com/en/developer/ruby-driver/3.0/features/
In my model I'm doing the following:
class User < ApplicationRecord
require 'cassandra'
def initialize
@cluster = Cassandra.cluster
end
def session
@cluster.connect('capsula')
end
def total_users
result = session.execute("SELECT * FROM users")
result.size
end
end
But when I call the total_users method
the error is shown:
undefined method `connect' for nil:NilClass
def session
@cluster.connect('capsula')
end
I wanted to save the connection on a variable so it would not be necessary to make a new connection for each request.