Reputation: 57
I just recently started learning firebase and i need assistance in connecting firebase with my ruby project.How can i save user data to firebase and get the data again?
Upvotes: 2
Views: 3169
Reputation: 611
I am going to make a few assumptions here:
You have completed Configuring Firebase (see firebase docs):
1.) Created a Firebase Project
2.) Did Firebase Project Settings
3.) Got Firebase Database Credential
Now, we can move on to fun stuff --> Rails:
1.) Install the 3rd party firebase library gem install firebase
make sure you crawl the documentation at https://github.com/oscardelben/firebase-ruby
2.) Make a module to hold all your firebase logic Right now there are there are only simple crud operations supported by the gem set(path, data, query_options)
get(path, query_options)
push(path, data, query_options)
delete(path, query_options)
update(path, data, query_options)
Example:
class ExampleClass
attr_reader :firebase
def initialize
@firebase = Firebase::Client.new(ENV[‘FIREBASE_DATABASE_URL’],
ENV[‘FIREBASE_DATABASE_SECRET’])
end
def get(path)
@firebase.get(path)
end
def set(path, data)
@firebase.set(path, data)
end
def delete(path)
@firebase.delete(path)
end
def push(path, data)
@firebase.push(path, data)
end
def update(path, data)
@firebase.update(path, data)
end
end
That should get you started/going, go through the docs for this gem as it is relatively lightweight and straightforward and the firebase documentation is really good.
Cheers
Upvotes: 4