Skip to content

Instantly share code, notes, and snippets.

@jaymcgavren
Created October 26, 2017 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymcgavren/d551eb17652e529cc2a8a91df12e9925 to your computer and use it in GitHub Desktop.
Save jaymcgavren/d551eb17652e529cc2a8a91df12e9925 to your computer and use it in GitHub Desktop.
A single-file Rails 5 application.
<!-- NOTE this file must be saved under a folder named "a_subfolder"! -->
<h1>a_template</h1>
<h1><%= @a_variable.an_attribute %></h1>
# Based on https://gist.github.com/trevorturk/91cb43c79e71e3d23649f6d103217de7
# To run, cd to directory where this file is saved, and run "rackup".
# Then open http://localhost:9292/apath in your browser.
require 'action_controller/railtie'
require 'active_record'
class AnApp < Rails::Application
routes.append do
get "/apath", to: "a#anaction"
end
config.secret_key_base = "a" * 30
config.eager_load = false
config.logger = Logger.new(STDOUT)
end
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'development.sqlite3'
)
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class AModel < ApplicationRecord
self.table_name = "a_table"
end
class ApplicationController < ActionController::Base
prepend_view_path "."
end
class AController < ApplicationController
def anaction
@a_variable = AModel.first
render "a_subfolder/a_template"
end
end
AnApp.initialize!
run AnApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment