私は、Webアプリケーションのためのシナトラのあなたの選択を好きで、データベースアダプタのSequelを示唆しています。ここでは短い、テストされていないアプリです:
require 'sinatra'
require 'sequel'
require 'haml'
DB = Sequel.connect('sqlite://blog.db')
get '/' do
@entries = DB[:posts].filter(live:true).order(:posted_on.desc).all
haml 'home' # finds 'views/home.haml' and makes a string
end
get '/:postname' do
@post = DB[:posts][short: params[:postname]]
haml 'post'
end
home.haml
- # this will be wrapped in layout.haml if you have one
%h1 My Posts
%p Welcome to my site, I hope you like it.
#posts
- @entries.each do |post|
%h2{id:post[:short]}
%a{href:post[:short]}= post[:title]
%p= post[:overview]
post.haml
%h1= @post[:title]
%p#overview= @post[:overview]
#contents= @post[:html]
シナトラへの完全な導入、続編、またはHAML外ですスタックオーバーフローの範囲。これはあなたが始めることを願っています。
"http'プロトコルが必要ない場合はどういう意味ですか? –
@SergioTulentsev "とし、そのデータをHTMLファイル**にフォーマットします。それでなぜ「シナトラ」は? –
@ VictorMorozああ、その部分を逃した。はい、OPがちょっと混乱しているようです。 –