Skip to content

Commit 25eb99a

Browse files
committed
Updated example to use new neo4j 1.0.0.beta.1
1 parent 54e0bfa commit 25eb99a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4471
-2327
lines changed

Gemfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'rails', '3.0.0'
4+
5+
# Bundle edge Rails instead:
6+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
7+
8+
if defined?(JRUBY_VERSION)
9+
gem 'activerecord-jdbc-adapter'
10+
gem 'jdbc-sqlite3', :require => false
11+
else
12+
gem 'sqlite3-ruby', :require => 'sqlite3'
13+
end
14+
15+
16+
gem 'neo4j', '1.0.0.beta.1'
17+
# Use unicorn as the web server
18+
# gem 'unicorn'
19+
20+
# Deploy with Capistrano
21+
# gem 'capistrano'
22+
23+
# To use debugger
24+
# gem 'ruby-debug'
25+
26+
# Bundle the extra gems:
27+
# gem 'bj'
28+
# gem 'nokogiri'
29+
# gem 'sqlite3-ruby', :require => 'sqlite3'
30+
# gem 'aws-s3', :require => 'aws/s3'
31+
32+
# Bundle gems for the local environment. Make sure to
33+
# put test-only gems in this group so their generators
34+
# and rake tasks are available in development mode:
35+
# group :development, :test do
36+
# gem 'webrat'
37+
# end

Gemfile.lock

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
abstract (1.0.0)
5+
actionmailer (3.0.0)
6+
actionpack (= 3.0.0)
7+
mail (~> 2.2.5)
8+
actionpack (3.0.0)
9+
activemodel (= 3.0.0)
10+
activesupport (= 3.0.0)
11+
builder (~> 2.1.2)
12+
erubis (~> 2.6.6)
13+
i18n (~> 0.4.1)
14+
rack (~> 1.2.1)
15+
rack-mount (~> 0.6.12)
16+
rack-test (~> 0.5.4)
17+
tzinfo (~> 0.3.23)
18+
activemodel (3.0.0)
19+
activesupport (= 3.0.0)
20+
builder (~> 2.1.2)
21+
i18n (~> 0.4.1)
22+
activerecord (3.0.0)
23+
activemodel (= 3.0.0)
24+
activesupport (= 3.0.0)
25+
arel (~> 1.0.0)
26+
tzinfo (~> 0.3.23)
27+
activerecord-jdbc-adapter (0.9.7-java)
28+
activeresource (3.0.0)
29+
activemodel (= 3.0.0)
30+
activesupport (= 3.0.0)
31+
activesupport (3.0.0)
32+
arel (1.0.1)
33+
activesupport (~> 3.0.0)
34+
builder (2.1.2)
35+
erubis (2.6.6)
36+
abstract (>= 1.0.0)
37+
i18n (0.4.1)
38+
jdbc-sqlite3 (3.6.3.054)
39+
mail (2.2.6.1)
40+
activesupport (>= 2.3.6)
41+
mime-types
42+
treetop (>= 1.4.5)
43+
mime-types (1.16)
44+
neo4j (1.0.0.beta.1)
45+
activemodel (~> 3.0.0)
46+
railties (~> 3.0.0)
47+
polyglot (0.3.1)
48+
rack (1.2.1)
49+
rack-mount (0.6.13)
50+
rack (>= 1.0.0)
51+
rack-test (0.5.4)
52+
rack (>= 1.0)
53+
rails (3.0.0)
54+
actionmailer (= 3.0.0)
55+
actionpack (= 3.0.0)
56+
activerecord (= 3.0.0)
57+
activeresource (= 3.0.0)
58+
activesupport (= 3.0.0)
59+
bundler (~> 1.0.0)
60+
railties (= 3.0.0)
61+
railties (3.0.0)
62+
actionpack (= 3.0.0)
63+
activesupport (= 3.0.0)
64+
rake (>= 0.8.4)
65+
thor (~> 0.14.0)
66+
rake (0.8.7)
67+
thor (0.14.1)
68+
treetop (1.4.8)
69+
polyglot (>= 0.3.1)
70+
tzinfo (0.3.23)
71+
72+
PLATFORMS
73+
java
74+
75+
DEPENDENCIES
76+
activerecord-jdbc-adapter
77+
jdbc-sqlite3
78+
neo4j (= 1.0.0.beta.1)
79+
rails (= 3.0.0)
Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,49 @@
11
class ActorsController < ApplicationController
2-
# before_filter :find_actor, :only => [:show, :edit, :update, :destroy, :link, :unlink]
3-
around_filter :neo_tx
4-
5-
2+
around_filter Neo4j::Rails::Transaction, :only => [:edit, :update, :destroy, :create]
3+
64
def index
7-
@actors = Actor.all.nodes
8-
end
9-
10-
def create
11-
@actor = Actor.new
12-
@actor.update(params[:actor])
13-
flash[:notice] = 'Actor was successfully created.'
14-
redirect_to(@actor)
15-
end
16-
17-
def update
18-
@actor.update(params[:actor])
19-
flash[:notice] = 'Actor was successfully updated.'
20-
redirect_to(@actor)
5+
@actors = Actor.all
216
end
22-
23-
def destroy
24-
@actor.del
25-
redirect_to(actors_url)
26-
end
27-
28-
def edit
29-
end
30-
7+
318
def show
32-
@movies = Movie.all.nodes
9+
@actor = Actor.find(params[:id])
10+
puts "FOUND ACTOR #{@actor}"
3311
end
34-
35-
def link
36-
@movie = Neo4j.load_node(params[:movie_id])
37-
rel1 = @actor.acted_in.new(@movie)
38-
rel1.character = params[:character]
39-
redirect_to(@actor)
12+
13+
def new
14+
@actor = Actor.new
4015
end
4116

42-
def unlink
43-
relationship = Neo4j.load_rel(params[:rel_id])
44-
relationship.del
45-
redirect_to(@actor)
17+
def edit
18+
@actor = Actor.find(params[:id])
4619
end
47-
48-
def new
49-
@actor = Actor.value_object.new
20+
21+
def create
22+
@actor = Actor.new(params[:actor])
23+
24+
if @actor.save
25+
redirect_to(@actor, :notice => 'Actor was successfully created.')
26+
else
27+
render :action => "new"
28+
end
29+
5030
end
51-
52-
private
53-
54-
def find_actor
55-
@actor = Neo4j.load_node(params[:id])
31+
32+
33+
def update
34+
@actor = Actor.find(params[:id])
35+
if @actor.update_attributes(params[:actor])
36+
redirect_to(@actor, :notice => 'Actor was successfully updated.')
37+
else
38+
render :action => "edit"
39+
end
5640
end
57-
58-
private
59-
60-
def neo_tx
61-
Neo4j::Transaction.new
62-
@actor = Neo4j.load_node(params[:id]) if params[:id]
63-
yield
64-
Neo4j::Transaction.finish
41+
42+
43+
def destroy
44+
@actor = Actor.find(params[:id])
45+
@actor.destroy
46+
redirect_to(actors_url)
6547
end
6648
end
49+
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# Filters added to this controller apply to all controllers in the application.
2-
# Likewise, all the methods added will be available for all controllers.
3-
41
class ApplicationController < ActionController::Base
5-
helper :all # include all helpers, all the time
6-
protect_from_forgery # See ActionController::RequestForgeryProtection for details
7-
8-
# Scrub sensitive parameters from your log
9-
# filter_parameter_logging :password
2+
protect_from_forgery
103
end
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
class UsersController < ApplicationController
2+
# GET /users
3+
# GET /users.xml
4+
def index
5+
@users = User.all
6+
7+
respond_to do |format|
8+
format.html # index.html.erb
9+
format.xml { render :xml => @users }
10+
end
11+
end
12+
13+
# GET /users/1
14+
# GET /users/1.xml
15+
def show
16+
@user = User.find(params[:id])
17+
18+
respond_to do |format|
19+
format.html # show.html.erb
20+
format.xml { render :xml => @user }
21+
end
22+
end
23+
24+
# GET /users/new
25+
# GET /users/new.xml
26+
def new
27+
@user = User.new
28+
29+
respond_to do |format|
30+
format.html # new.html.erb
31+
format.xml { render :xml => @user }
32+
end
33+
end
34+
35+
# GET /users/1/edit
36+
def edit
37+
@user = User.find(params[:id])
38+
end
39+
40+
# POST /users
41+
# POST /users.xml
42+
def create
43+
@user = User.new(params[:user])
44+
45+
respond_to do |format|
46+
if @user.save
47+
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
48+
format.xml { render :xml => @user, :status => :created, :location => @user }
49+
else
50+
format.html { render :action => "new" }
51+
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
52+
end
53+
end
54+
end
55+
56+
# PUT /users/1
57+
# PUT /users/1.xml
58+
def update
59+
@user = User.find(params[:id])
60+
61+
respond_to do |format|
62+
if @user.update_attributes(params[:user])
63+
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
64+
format.xml { head :ok }
65+
else
66+
format.html { render :action => "edit" }
67+
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
68+
end
69+
end
70+
end
71+
72+
# DELETE /users/1
73+
# DELETE /users/1.xml
74+
def destroy
75+
@user = User.find(params[:id])
76+
@user.destroy
77+
78+
respond_to do |format|
79+
format.html { redirect_to(users_url) }
80+
format.xml { head :ok }
81+
end
82+
end
83+
end

app/helpers/actors_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ActorsHelper
2+
end

app/helpers/application_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
# Methods added to this helper will be available to all templates in the application.
21
module ApplicationHelper
32
end

app/helpers/users_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module UsersHelper
2+
end

app/models/actor.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
class Actor
2-
include Neo4j::NodeMixin
3-
property :name, :phone, :salary
4-
has_n(:acted_in).to(Movie).relationship(Role)
5-
index :name
6-
end
1+
class Actor < Neo4j::Model
2+
rule(:all)
3+
4+
property :name
5+
property :born
6+
end

app/views/actors/_form.html.erb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<%= form_for(@actor) do |f| %>
2+
<% if @actor.errors.any? %>
3+
<div id="error_explanation">
4+
<h2><%= pluralize(@actor.errors.count, "error") %> prohibited this actor from being saved:</h2>
5+
6+
<ul>
7+
<% @actor.errors.full_messages.each do |msg| %>
8+
<li><%= msg %></li>
9+
<% end %>
10+
</ul>
11+
</div>
12+
13+
14+
<% end %>
15+
16+
17+
<%= f.label :name, 'Name' %>:
18+
<%= f.text_field :name %><br />
19+
<%= f.label :born, 'Born' %>:
20+
<%= f.text_field :born %><br />
21+
22+
23+
<div class="actions">
24+
<%= f.submit %>
25+
</div>
26+
<% end %>

0 commit comments

Comments
 (0)