Đi đoạn mã sau:Sinatra Variable Phạm vi
### Dependencies
require 'rubygems'
require 'sinatra'
require 'datamapper'
### Configuration
config = YAML::load(File.read('config.yml'))
name = config['config']['name']
description = config['config']['description']
username = config['config']['username']
password = config['config']['password']
theme = config['config']['theme']
set :public, 'views/themes/#{theme}/static'
### Models
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/marvin.db")
class Post
include DataMapper::Resource
property :id, Serial
property :name, String
property :body, Text
property :created_at, DateTime
property :slug, String
end
class Page
include DataMapper::Resource
property :id, Serial
property :name, String
property :body, Text
property :slug, String
end
DataMapper.auto_migrate!
### Controllers
get '/' do
@posts = Post.get(:order => [ :id_desc ])
haml :"themes/#{theme}/index"
end
get '/:year/:month/:day/:slug' do
year = params[:year]
month = params[:month]
day = params[:day]
slug = params[:slug]
haml :"themes/#{theme}/post.haml"
end
get '/:slug' do
haml :"themes/#{theme}/page.haml"
end
get '/admin' do
haml :"admin/index.haml"
end
Tôi muốn làm name
, và tất cả những biến sẵn cho toàn bộ kịch bản, cũng như các quan điểm. Tôi đã cố gắng biến chúng thành các biến toàn cầu, nhưng không có con xúc xắc.
Sử dụng 'options' sẽ không hãy cảnh báo: các tùy chọn 'Sinatra :: Base # không được chấp nhận và sẽ bị xóa, sử dụng #settings thay thế.' Sử dụng' settings' để thay thế. – briangonzalez