[RUBY] I want to play with Firestore from Rails

I will post it as a memo.

0. Premise

--rails new completed --Project created with firebase

1. gem installation

gem "google-cloud-firestore"

2. Private key generation

Download the json file from "Settings" → "Generate new private key" Put it in your Rails project

3. Other settings

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new(
  
  #Here is my project ID
  project_id: "my-project" ,
  #Here "2.Specify the path of the json file of "Generate private key"
  credentials: "/path/to/keyfile.json"

)

4. Get the data above

  1. Data acquisition
test_val = firestore.col("test_col").doc("test_doc").get().data[:test_field]
  1. Data storage

~ Scheduled to be added ~

  1. Data update

~ Scheduled to be added ~

  1. Delete data

~ Scheduled to be added ~

5. Reference

-farebase official document

-StudyPlus Developer Blog

-README.md of the above gem

Recommended Posts

I want to play with Firestore from Rails
[Rails] I want to load CSS with webpacker
I want to authenticate users to Rails with Devise + OmniAuth
I want to redirect sound from Ubuntu with xrdp
I want to push an app made with Rails 6 to GitHub
I want to use DBViewer with Eclipse 2018-12! !!
I want to convert an array to Active Record Relation with Rails
[Rails] I want to add data to Params when transitioning with link_to
I want to test Action Cable with RSpec test
Run R from Java I want to run rJava
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I want to graduate from npm install properly [2020]
I want to use java8 forEach with index
I want to mess with Permission of Windows directory from WSL (ubuntu)
I want to write quickly from java to sqlite
I want to introduce the committee with Rails without getting too dirty
I want to perform aggregation processing with spring-batch
I want to be able to read a file using refile with administrate [rails6]
Rails6 I want to make an array of values with a check box
[Rails] I want to test with RSpec. We support your step [Introduction procedure]
[Java] I want to calculate the difference from the date
I want to use a little icon in Rails
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
I want to define a function in Rails Console
I want to transition screens with kotlin and java!
I want to get along with Map [Java beginner]
I want to connect to Heroku MySQL from a client
Java to play with Function
I want to convert characters ...
I want to hit the API with Rails on multiple docker-composes set up locally
[Rails] [bootstrap] I want to change the font size responsively
[Rails] I tried to create a mini app with FullCalendar
I was addicted to setting default_url_options with Rails devise introduction
I want to create a form to select the [Rails] category
[Rails] I tried to implement batch processing with Rake task
I want to manually send an authorization email with Devise
I want to distinct the duplicated data with has_many through
I want to implement various functions with kotlin and java!
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I want to pass the startup command to postgres with docker-compose.
[Java] I want to test standard input & standard output with JUnit
I want to fetch another association of the parent model from the intermediate table with has_many
After posting an article with Rails Simple Calendar, I want to reflect it in the calendar.
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I want to recreate the contents of assets from scratch in the environment built with capistrano
I want to use FormObject well
I want to convert InputStream to String
I tried to interact with Java
Connect to Rails server with iPhone
How to get along with Rails
Introducing React to Rails with react-rails
Update MySQL from 5.7 to 8.0 with Docker
I want to make a button with a line break with link_to [Note]
I want to connect SONY headphones WH-1000XM4 with LDAC on ubuntu 20.04! !!
I want to hook log file generation / open with log4j # FileAppender
I want to return to the previous screen with kotlin and java!
I want to INSERT Spring Local Time with MySQL Time (also milliseconds)
I want to avoid OutOfMemory when outputting large files with POI
I tried to implement the image preview function with Rails / jQuery
I want to operate cron with GUI, so I will install Dkron