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