Rails3.2.x で ripple を使う

Riak の ruby用の ORM の ripple をRails 3.2系で使う。

require 'ripple/railtie'
# rails g ripple をして必要ファイルを生成すること
view raw application.rb hosted with ❤ by GitHub
class Article
include Ripple::Document
property :title, String
property :body, String, presence:true
one :user
end
view raw article.rb hosted with ❤ by GitHub
gem 'ripple', "~>1.0.0.beta2"
view raw Gemfile hosted with ❤ by GitHub
class User
include Ripple::Document
property :name, String
property :login, String, presence:true
index :login, String
many :articles
end
view raw user.rb hosted with ❤ by GitHub
> u = User.create(name:'CHU', login:'chu')
=> <User:o8fmcna88jctpxghshj7j5oncr9 login="chu" name="CHU">
> u.articles < < Article.create(title:"Hello world")
=> <Article:rsfkusim2keemw62kmtwjbjzo7n title="Hello world" body=nil>
> u.save
=> true
> User.find('7MtYxfhCObVSBqPX7DlEQYA5rtY')
=> <User:o8fmcna88jctpxghshj7j5oncr9 login="chu" name="CHU">
> User.find_by_index(:login, 'chu')
=> [<User:o8fmcna88jctpxghshj7j5oncr9 login="chu" name="CHU">]
view raw z.rb hosted with ❤ by GitHub

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です