Skip to content

Instantly share code, notes, and snippets.

@ta1kt0me
Created October 21, 2015 16:17
Show Gist options
  • Save ta1kt0me/0bf399079049752ae400 to your computer and use it in GitHub Desktop.
Save ta1kt0me/0bf399079049752ae400 to your computer and use it in GitHub Desktop.
(大体)Single file Rails Application - https://github.com/suburi/simple-app
require './mini_app'
run MiniApp::Application
source "https://rubygems.org"
gem "rails"
gem "sqlite3"
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'
#!/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