使用neo4j base on rails 建立一個微型討論區

2014-11-28, Friday
ruby

最近在修 social network graph analysis 的課

有同學介紹neo4j 就google了一下 是否有rails的相關應用

看到了neo4jrb,感覺蠻不錯的.

大概照著做了一下.有空可以好好的研究看看!

學習筆記:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
install jruby
rvm list |grep jruby
=> jruby-1.7.11 [ x86_64 ]

rvm list
rails new new_neo4j -m http://neo4jrb.github.com/neo4j/neo4j.rb -O
cd new_neo4j
bundle
rake neo4j:install[community-2.1.4,development]
#start neo4j
rake neo4j:config[development,7000]
rake neo4j:start


#vim config/environments/development.rb
-> config.neo4j.session_type :server_db
-> config.neo4j.session_path = 'http://localhost:7000'

#execute
rails g scaffold post title body
rails g scaffold comment body

# edit models
# app/models/comment.rb
-> has_one :out, :post, type: :comments_on

# edit models
# app/models/post.rb
-> has_many :in, :comments, origin: :post

#start the rails
rails s

#open browser
#http://localhost:3000/posts

#if you got this problem
##OpenSSL::Cipher::CipherError: Illegal key size: possibly you need to install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for your JRE

#Sol:
Create config/initializers/unlimited_strength_cryptography.rb:

if RUBY_PLATFORM == 'java' # Allows the application to work with other Rubies if not JRuby
  require 'java'
  java_import 'java.lang.ClassNotFoundException'

  begin
    security_class = java.lang.Class.for_name('javax.crypto.JceSecurity')
    restricted_field = security_class.get_declared_field('isRestricted')
    restricted_field.accessible = true
    restricted_field.set nil, false
  rescue ClassNotFoundException => e
    # Handle Mac Java, etc not having this configuration setting
    $stderr.print "Java told me: #{e}n"
  end
end

詳細過程 Youtube.