found a way to pass rails app data to javascript function. Also added database relations to models