sinator
1.0.0
Sinator เป็นเครื่องกำเนิดแอปพลิเคชัน Sinatra มันจะสร้างแอปพลิเคชัน Sinatra ด้วยการกำหนดค่าขั้นต่ำ เหตุผลที่อยู่เบื้องหลังโครงการนี้เพราะฉันต้องการสร้างเว็บแอปพลิเคชันขนาดเล็กจำนวนมากตาม Sinatra กับ Ruby Gems ของบุคคลที่สามเป็นรากฐาน
gem install sinatorด้วย Bundler ใส่รหัสนี้ใน Gemfile ของคุณ:
gem 'sinator'สร้างแอพในไดเรกทอรีปัจจุบันโดยไม่มีฐานข้อมูล
sinator -n my_app
สร้างแอพในไดเรกทอรีเป้าหมายโดยไม่มีฐานข้อมูล
sinator -n my_app -t target/dir
สร้างแอพในไดเรกทอรีปัจจุบันด้วยฐานข้อมูล -d ตัวเลือกจะสร้างแอพด้วยอะแดปเตอร์ Sequel และอะแดปเตอร์ PostgreSQL
sinator -n my_app -d
เรียกใช้เว็บเซิร์ฟเวอร์บน LocalHost
bundle exec puma
เรียกใช้คอนโซลแอปพลิเคชัน / โหมดอินเทอร์แอคทีฟ / IRB
bundle exec tux
ตัวอย่างนี้สมมติว่า PostgreSQL กำลังทำงานอยู่แล้ว ดู github.com/kuntoaji/todo_sinator สำหรับแอปพลิเคชัน todo ที่สร้างขึ้นด้วย Sinator
sinator -n my_app -dmy_appbundle installconfig/database.ymlcreatedb my_app_developmentdb/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