2

我想将一个纯 ruby​​ 数据库(kirbybase http://www.netpromi.com/files/kirbybase_ruby_manual.html)与 Sinatra 一起使用,所以在 ruby​​ 中我们会有这样的东西来显示记录:

require 'kirbybase'
db = KirbyBase.new
cars_tbl= db.get_table(:cars)
ferrari = cars_tbl.select { |r| r.recno == 9 }
puts ferrari

或所有记录

results = cars_tbl.select(:name,:race,:color,:recno).sort(+:color)

在不混淆“rubysh”kirbybase语法的情况下将其与Sinatra集成的最佳方法是什么?

4

1 回答 1

2

要了解sinatra-redis的书,您可以执行以下操作:

require 'sinatra'
require 'kirbybase'

helpers do
  # Create a helper to allow easier access to settings.kirby
  # Name it whatever you want
  def kirby
    settings.kirby
  end
end

configure do
  # Initialise kirby
  set :kirby, KirbyBase.new
end

get '/' do
  cars_tbl = kirby.get_table(:cars)
  ferrari = cars_tbl.select { |r| r.recno == 9 }
  "Car is #{ferrari}"
end
于 2012-04-12T18:44:46.770 回答