Skip to content

Instantly share code, notes, and snippets.

@agilous
Last active January 17, 2023 20:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agilous/af886a0a847f24464c0f643c49e1c4a6 to your computer and use it in GitHub Desktop.
Save agilous/af886a0a847f24464c0f643c49e1c4a6 to your computer and use it in GitHub Desktop.
Single Page Rails App

Single Page Rails App

Credit to @GregMolnar.

Run the app

This has only been tested with Ruby 3.1.2. YMMV.

rackup app.ru
development.sqlite3
/log
# frozen_string_literal: true
## Credit: https://twitter.com/GregMolnar/status/1556964177520066560
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'puma'
gem 'rails'
gem 'sqlite3'
end
require 'rails/all'
database = 'development.sqlite3'
ENV['DATABASE_URL'] = "sqlite3:#{database}"
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: database)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
end
class Post < ActiveRecord::Base
end
class App < Rails::Application
config.root = __dir__
config.consider_all_requests_local = true
config.eager_load = false
config.active_record.legacy_connection_handling = false
config.secret_key_base = 'i_am_a_secret'
config.active_storage.service_configurations = { 'local' => { 'service' => 'Disk', 'root' => './storage' } }
routes.append do
root to: 'welcome#index'
end
end
class WelcomeController < ActionController::Base
def index
render inline: 'Hi!'
end
end
App.initialize!
run App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment