-
-
Save johnpaulashenfelter/870d25ce9ea02b163ef3747dd5fd4755 to your computer and use it in GitHub Desktop.
Single file Rails 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
# the new and improved one-file rails app -- now including | |
require "action_controller/railtie" | |
class Tester < Rails::Application | |
config.session_store :cookie_store, :key => '_rails_session' | |
config.secret_token = '095f674153982a9ce59914b561f4522a' | |
end | |
class UsersController < ActionController::Base | |
def current | |
render text: current_user.server_id | |
end | |
def create | |
@u = User.create(params[:user]) | |
@u.create_remotely! | |
session[:user_id] = @u.id | |
render text: "good!" | |
end | |
end | |
require 'sqlite3' | |
db_file = File.join(File.dirname(__FILE__), 'test.sqlite3') | |
db = SQLite3::Database.new( db_file ) | |
db.execute( "drop table users;" ) rescue nil # maybe it didn't exist! | |
db.execute( "create table users (id integer primary key autoincrement, email varchar(100), server_id integer);" ) | |
require 'active_record' | |
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => db_file) | |
class User < ActiveRecord::Base | |
include Whoami::Rails::ActiveRecord | |
end | |
Tester.routes.draw do | |
root to: 'users#current' | |
match '/users/current' => 'users#current' | |
resources :users | |
end |
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 './application' | |
run Tester |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment