Created
October 21, 2015 16:17
-
-
Save ta1kt0me/0bf399079049752ae400 to your computer and use it in GitHub Desktop.
(大体)Single file Rails Application - https://github.com/suburi/simple-app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './mini_app' | |
run MiniApp::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "rails" | |
gem "sqlite3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
require 'action_controller/railtie' | |
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') | |
module MiniApp | |
class Application < Rails::Application | |
config.secret_token = [*'A'..'z'].join | |
config.session_store :cookie_store, :key => '_miniapp_session' | |
config.eager_load = false | |
end | |
end | |
MiniApp::Application.initialize! | |
module ApplicationHelper; end | |
class ApplicationController < ActionController::Base | |
end | |
class BooksController < ApplicationController | |
def index | |
@books = Book.all | |
render :inline => <<-ERB | |
<%= 'Hello World' %> | |
ERB | |
end | |
end | |
MiniApp::Application.routes.draw do | |
root 'books#index' | |
resources :books | |
end | |
class Book < ActiveRecord::Base | |
end | |
class CreateAllTables < ActiveRecord::Migration | |
def self.up | |
create_table :books do |t| | |
t.string :title | |
t.integer :price | |
end | |
Book.create title: "Alice's Adventures in Wonderland", price: 500 | |
end | |
end | |
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'books' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
bundle exec rackup -p 3000 ./config.ru |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment