निम्नलिखित कोड डालें:सिनात्रा चर का दायरा
### 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
मैं name
बनाना चाहते हैं, और उन सभी चर पूरी स्क्रिप्ट के लिए उपलब्ध है, साथ ही देखा गया। मैंने उन्हें वैश्विक चर बनाने की कोशिश की, लेकिन कोई पासा नहीं।
का उपयोग करते हुए 'options' होगा कोई बाद सर्वर को पुनः आरंभ करने एक चेतावनी फेंक दें: 'सिनात्रा :: बेस # विकल्प बहिष्कृत किए गए हैं और हटा दिए जाएंगे, इसके बजाय #settings का उपयोग करें। इसके बजाय' सेटिंग्स' का उपयोग करें। – briangonzalez