Sinatra application generator
Sinator is Sinatra application generator. It will generate Sinatra application with minimum configuration.
The reasons behind this project because I want to create many small web application based on sinatra with other third party ruby gems as foundation.
gem install sinator
with Bundler, put this code in your Gemfile:
gem 'sinator'
Generate app in current directory without database.
sinator -n my_app
Generate app in target directory without database.
sinator -n my_app -t target/dir
Generate app in current directory with database. -d
option will generate app with Sequel
ORM and PostgreSQL adapter.
sinator -n my_app -d
Run web server on localhost.
bundle exec puma
Run application console / interactive mode / IRB.
bundle exec tux
This example assume that PostgreSQL is already running.
See github.com/kuntoaji/todo_sinator for Todo Application generated with Sinator.
sinator -n my_app -d
my_app
bundle install
config/database.yml
createdb my_app_development
.db/migrations/001_create_artists.rb
and put the following code:Sequel.migration do
up do
create_table(:artists) do
primary_key :id
String :name, :null=>false
end
end
down do
drop_table(:artists)
end
end
rake db:migrate
app/models/Artist.rb
and put the following code:class Artist < Sequel::Model
end
app/routes/artists.rb
and put the following code: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
end
app/views/artists/index.erb
and put the following code:<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