Sinator - Sinatra Application Generator
- Categories:
- sinatra
Sinator is a Sinatra based web application generator. Generated application is based on my use cases.
Generated application will be installed these Ruby Gems:
- sinatra
- sinatra-contrib
- encrypted_cookie
Sinatra::Reloader
in development environment only- puma as application server
Rack::Session::EncryptedCookie
Rack::Csrf
- sequel
- sequel_pg as PostgreSQL adapter
- sprockets
- sass
- uglifier
- tux for console
Installation
gem install sinator
with Bundler, put this code in your Gemfile:
gem 'sinator'
How to Use
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
Example Application
See github.com/kuntoaji/todo_sinator
Example Usage
This example assume that PostgreSQL is already running and desired database is already exist.
- run
sinator -n my_app -d
- cd
my_app
- run
bundle install
- configure your database setting in
config/database.yml
-
create file
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
- run
rake db:migrate
-
create file
app/models/Artist.rb
and put the following code:class Artist < Sequel::Model end
-
create file
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
-
create file
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>
- run the server
bundle exec puma
- open url
localhost:9292/artists
Sponsored Links
- Register to Digital Ocean cloud with this link and get $200 credit
- Looking for cheap CDN? Bunny is the answer
- Alternative Cloud besides AWS and Digital Ocean