sinator
1.0.0
Sinator是Sinatra應用生成器。它將以最低配置生成Sinatra應用程序。該項目背後的原因是因為我想以其他第三方Ruby Gems作為基礎創建許多基於Sinatra的小型Web應用程序。
gem install sinator使用Bundler,將此代碼放入您的gemfile:
gem 'sinator'在當前目錄中生成應用,而無需數據庫。
sinator -n my_app
在無數據庫的目標目錄中生成應用程序。
sinator -n my_app -t target/dir
使用數據庫在當前目錄中生成應用。 -d選項將使用Sequel ORM和PostgreSQL適配器生成應用。
sinator -n my_app -d
在Localhost上運行Web服務器。
bundle exec puma
運行應用程序控制台 /交互式模式 / IRB。
bundle exec tux
此示例假設PostgreSQL已經在運行。請參閱github.com/kuntoaji/todo_sinator,以獲取用罪人生成的待辦事項。
sinator -n my_app -dmy_appbundle installconfig/database.yml中配置數據庫設置createdb my_app_development創建數據庫。db/migrations/001_create_artists.rb ,並列出以下代碼: Sequel . migration do
up do
create_table ( :artists ) do
primary_key :id
String :name , :null => false
end
end
down do
drop_table ( :artists )
end
endrake db:migrateapp/models/Artist.rb並列出以下代碼: class Artist < Sequel :: Model
endapp/routes/artists.rb並列出以下代碼: class MyApp
get '/artists' do
@artists = Artist . all
erb :"artists/index"
end
post '/artists' do
@artist = Artist . new
@artist . name = params [ :name ]
@artist . save
redirect '/artists'
end
endapp/views/artists/index.erb ,並列出以下代碼: < h1 > List of Artist </ h1 >
< ul >
<% @artists . each do | artist | %>
< li > <%= artist . name %> </ li >
<% end %>
</ ul >
< form action =" /artists " method =" post " >
<%= Rack :: Csrf . tag ( env ) %>
< input type =" text " name =" name " />
< button > Submit </ button >
</ form >bundle exec pumalocalhost:9292/artists