Skip to content

Commit

Permalink
Updated example to use new neo4j 1.0.0.beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasronge committed Sep 21, 2010
1 parent 54e0bfa commit 25eb99a
Show file tree
Hide file tree
Showing 55 changed files with 4,471 additions and 2,327 deletions.
37 changes: 37 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

if defined?(JRUBY_VERSION)
gem 'activerecord-jdbc-adapter'
gem 'jdbc-sqlite3', :require => false
else
gem 'sqlite3-ruby', :require => 'sqlite3'
end


gem 'neo4j', '1.0.0.beta.1'
# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
79 changes: 79 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (= 3.0.0)
mail (~> 2.2.5)
actionpack (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4.1)
rack (~> 1.2.1)
rack-mount (~> 0.6.12)
rack-test (~> 0.5.4)
tzinfo (~> 0.3.23)
activemodel (3.0.0)
activesupport (= 3.0.0)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activerecord (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
arel (~> 1.0.0)
tzinfo (~> 0.3.23)
activerecord-jdbc-adapter (0.9.7-java)
activeresource (3.0.0)
activemodel (= 3.0.0)
activesupport (= 3.0.0)
activesupport (3.0.0)
arel (1.0.1)
activesupport (~> 3.0.0)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.4.1)
jdbc-sqlite3 (3.6.3.054)
mail (2.2.6.1)
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
mime-types (1.16)
neo4j (1.0.0.beta.1)
activemodel (~> 3.0.0)
railties (~> 3.0.0)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-test (0.5.4)
rack (>= 1.0)
rails (3.0.0)
actionmailer (= 3.0.0)
actionpack (= 3.0.0)
activerecord (= 3.0.0)
activeresource (= 3.0.0)
activesupport (= 3.0.0)
bundler (~> 1.0.0)
railties (= 3.0.0)
railties (3.0.0)
actionpack (= 3.0.0)
activesupport (= 3.0.0)
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
thor (0.14.1)
treetop (1.4.8)
polyglot (>= 0.3.1)
tzinfo (0.3.23)

PLATFORMS
java

DEPENDENCIES
activerecord-jdbc-adapter
jdbc-sqlite3
neo4j (= 1.0.0.beta.1)
rails (= 3.0.0)
91 changes: 37 additions & 54 deletions app/controllers/actors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,66 +1,49 @@
class ActorsController < ApplicationController
# before_filter :find_actor, :only => [:show, :edit, :update, :destroy, :link, :unlink]
around_filter :neo_tx


around_filter Neo4j::Rails::Transaction, :only => [:edit, :update, :destroy, :create]

def index
@actors = Actor.all.nodes
end

def create
@actor = Actor.new
@actor.update(params[:actor])
flash[:notice] = 'Actor was successfully created.'
redirect_to(@actor)
end

def update
@actor.update(params[:actor])
flash[:notice] = 'Actor was successfully updated.'
redirect_to(@actor)
@actors = Actor.all
end

def destroy
@actor.del
redirect_to(actors_url)
end

def edit
end


def show
@movies = Movie.all.nodes
@actor = Actor.find(params[:id])
puts "FOUND ACTOR #{@actor}"
end

def link
@movie = Neo4j.load_node(params[:movie_id])
rel1 = @actor.acted_in.new(@movie)
rel1.character = params[:character]
redirect_to(@actor)

def new
@actor = Actor.new
end

def unlink
relationship = Neo4j.load_rel(params[:rel_id])
relationship.del
redirect_to(@actor)
def edit
@actor = Actor.find(params[:id])
end

def new
@actor = Actor.value_object.new

def create
@actor = Actor.new(params[:actor])

if @actor.save
redirect_to(@actor, :notice => 'Actor was successfully created.')
else
render :action => "new"
end

end

private

def find_actor
@actor = Neo4j.load_node(params[:id])


def update
@actor = Actor.find(params[:id])
if @actor.update_attributes(params[:actor])
redirect_to(@actor, :notice => 'Actor was successfully updated.')
else
render :action => "edit"
end
end

private

def neo_tx
Neo4j::Transaction.new
@actor = Neo4j.load_node(params[:id]) if params[:id]
yield
Neo4j::Transaction.finish


def destroy
@actor = Actor.find(params[:id])
@actor.destroy
redirect_to(actors_url)
end
end

9 changes: 1 addition & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details

# Scrub sensitive parameters from your log
# filter_parameter_logging :password
protect_from_forgery
end
83 changes: 83 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class UsersController < ApplicationController
# GET /users
# GET /users.xml
def index
@users = User.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end

# GET /users/1
# GET /users/1.xml
def show
@user = User.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end

# GET /users/new
# GET /users/new.xml
def new
@user = User.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @user }
end
end

# GET /users/1/edit
def edit
@user = User.find(params[:id])
end

# POST /users
# POST /users.xml
def create
@user = User.new(params[:user])

respond_to do |format|
if @user.save
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end

# PUT /users/1
# PUT /users/1.xml
def update
@user = User.find(params[:id])

respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /users/1
# DELETE /users/1.xml
def destroy
@user = User.find(params[:id])
@user.destroy

respond_to do |format|
format.html { redirect_to(users_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/actors_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ActorsHelper
end
1 change: 0 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
12 changes: 6 additions & 6 deletions app/models/actor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Actor
include Neo4j::NodeMixin
property :name, :phone, :salary
has_n(:acted_in).to(Movie).relationship(Role)
index :name
end
class Actor < Neo4j::Model
rule(:all)

property :name
property :born
end
26 changes: 26 additions & 0 deletions app/views/actors/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%= form_for(@actor) do |f| %>
<% if @actor.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@actor.errors.count, "error") %> prohibited this actor from being saved:</h2>

<ul>
<% @actor.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>


<% end %>


<%= f.label :name, 'Name' %>:
<%= f.text_field :name %><br />
<%= f.label :born, 'Born' %>:
<%= f.text_field :born %><br />


<div class="actions">
<%= f.submit %>
</div>
<% end %>
24 changes: 4 additions & 20 deletions app/views/actors/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
<h1>Edit Actor</h1>
<h1>Editing actor</h1>

<% form_for(@actor) do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :phone %><br />
<%= f.text_field :phone %>
</p>
<p>
<%= f.label :salary%><br />
<%= f.text_field :salary %>
</p>
<p>
<%= f.submit "Update" %>
</p>
<%= render 'form' %>

<% end %>

<%= link_to 'Back', actors_path %>
<%= link_to 'Show', @actor %> |
<%= link_to 'Back', actors_path %>
Loading

0 comments on commit 25eb99a

Please sign in to comment.