参考 https://github.com/camping/camping/blob/master/book/02_getting_started.md 的例子
When The Camping Server boots up, it will automatically call Nuts.create
在代码中加上
def Nuts.create
Nuts::Models.create_schema
end
是初始化数据库表 但是 执行
camping ntuts.rb
可以访问模板页面,读数据库提示
SQLite3::SQLException: no such table: nuts_pages
在当前目录生成一个 nuts.db 手工建表也一样的提示
测试代码
require "camping"
require "camping/ar"
Camping.goes :Nuts
module Nuts
module Models
class Page < Base
end
class BasicFields < ActiveRecord::Migration[4.2] # < V 1.0
def self.up
create_table Nuts.page do |t|
t.string :title
t.text :content
# This gives us created_at and updated_at
t.timestamps
end
end
def self.down
drop_table Nuts.posts
end
end
end
module Controllers
module Nuts::Controllers
class Index < R "/"
def get
@pages = Page.all #(:select => "title")
render :list
# Time.now.to_s
end
end
end
end
module Views
def layout
html do
head do
title { "Nuts And GORP" }
end
body { self << yield }
end
end
def list
h1 "All pages"
ul do
@pages.each do |page|
li do
a page.title, :href => R(PageX, page.title)
end
end
end
end
end
end
def Nuts.create
Nuts::Models.create_schema
end