sinator
1.0.0
シナーターはシナトラアプリケーションジェネレーターです。最小構成でSinatraアプリケーションを生成します。このプロジェクトの背後にある理由は、Sinatraに基づいて他のサードパーティRuby Gemsを基礎として多くの小さなWebアプリケーションを作成したいからです。
gem install sinatorバンドラーを使用して、このコードをGemfileに入れてください。
gem 'sinator'データベースなしで現在のディレクトリでアプリを生成します。
sinator -n my_app
データベースなしでターゲットディレクトリでアプリを生成します。
sinator -n my_app -t target/dir
データベースを使用して現在のディレクトリでアプリを生成します。 -dオプションは、 Sequel ORMとPostgreSQLアダプターを使用してAPPを生成します。
sinator -n my_app -d
LocalHostでWebサーバーを実行します。
bundle exec puma
アプリケーションコンソール /インタラクティブモード / IRBを実行します。
bundle exec tux
この例は、PostgreSQLがすでに実行されていると仮定しています。 sinatorで生成されたtodoアプリケーションについては、github.com/kuntoaji/todo_sinatorを参照してください。
sinator -n my_app -dを実行しますmy_appbundle installを実行しますconfig/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 pumaを実行しますlocalhost:9292/artists