Book Image

Neo4j Cookbook

By : Ankur goel, Ankur Goel
Book Image

Neo4j Cookbook

By: Ankur goel, Ankur Goel

Overview of this book

Table of Contents (17 chapters)
Neo4j Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Accessing the embedded Neo4j from Ruby


Many modern web apps are built on Ruby and Rails, so it is important to learn how to access Neo4j embedded using Ruby.

Getting ready

Andreas Ronge has written the Ruby bindings in JRuby, which utilizes the neo4j Java library underneath it. It can be embedded into an existing Rails application very easily.

This project can be accessed at https://github.com/neo4jrb/neo4j-core.

This project comes with an excellent documentation on how to use it with the Rail application.

How to do it...

Install gem neo4j-core on the machine, using the gem install neo4j-core command.

The complete documentation has been provided at https://github.com/neo4jrb/neo4j-core/wiki.

One sample example of creating nodes and relationships is shown as follows:

node = Neo4j::Node.create({name: 'neo'}, :hero, :human)
puts "Created node #{node[:name]} with labels #{node.labels.join(', ')}"

n1 = Neo4j::Node.create
n2 = Neo4j::Node.create
rel = n1.create_rel(:knows, n2, since: 2015)

How it works...