Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # server.rb
- require 'sinatra'
- require "sinatra/namespace"
- require 'mongoid'
- # DB Setup
- Mongoid.load! "mongoid.config"
- # Models
- class Book
- include Mongoid::Document
- field :title, type: String
- field :author, type: String
- field :isbn, type: String
- validates :title, presence: true
- validates :author, presence: true
- validates :isbn, presence: true
- index({ title: 'text' })
- index({ isbn: 1 }, { unique: true, name: "isbn_index" })
- scope :title, -> (title) { where(title: /^#{title}/) }
- scope :isbn, -> (isbn) { where(isbn: isbn) }
- scope :author, -> (author) { where(author: author) }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement