Created
April 25, 2024 17:15
-
-
Save mediafinger/31f32e32eac498fd39e2d84f6f7f9006 to your computer and use it in GitHub Desktop.
Single Page Rails App example / template
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
# filename: single_page_rails_app.ru | |
# RUN via: `rackup single_page_rails_app.ru` | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "rack", "2.2.9" | |
gem "rails", "~> 7.1" | |
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| | |
t.text :content | |
end | |
create_table :comments, force: true do |t| | |
t.integer :post_id | |
t.text :content | |
end | |
end | |
class App < Rails::Application | |
config.root = __dir__ | |
config.consider_all_requests_local = true | |
config.secret_key_base = "i_am_a_secret" | |
config.active_storage.service_configurations = { "local" => { "service" => "Disk", "root" => "./storage" } } | |
config.log_level = :debug | |
config.logger = Logger.new($stdout) | |
routes.append do | |
root to: "welcome#index" | |
end | |
end | |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :post | |
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