Skip to content

Instantly share code, notes, and snippets.

@johnpaulashenfelter
Forked from shawndrost/application.rb
Created October 19, 2017 11:13
Show Gist options
  • Select an option

  • Save johnpaulashenfelter/870d25ce9ea02b163ef3747dd5fd4755 to your computer and use it in GitHub Desktop.

Select an option

Save johnpaulashenfelter/870d25ce9ea02b163ef3747dd5fd4755 to your computer and use it in GitHub Desktop.

Revisions

  1. @shawndrost shawndrost revised this gist Jan 17, 2012. 2 changed files with 30 additions and 7 deletions.
    35 changes: 29 additions & 6 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,39 @@
    # the new and improved one-file rails app -- now including

    require "action_controller/railtie"

    class Application < Rails::Application
    class Tester < Rails::Application
    config.session_store :cookie_store, :key => '_rails_session'
    config.secret_token = '095f674153982a9ce59914b561f4522a'
    end

    class PagesController < ActionController::Base
    def index
    render :text => "Hello, world!"
    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

    Application.routes.draw do
    get '/' => 'pages#index'
    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
    2 changes: 1 addition & 1 deletion config.ru
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    require './application'
    run Application
    run Tester
  2. @dgb dgb created this gist Nov 21, 2011.
    16 changes: 16 additions & 0 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    require "action_controller/railtie"

    class Application < Rails::Application
    config.session_store :cookie_store, :key => '_rails_session'
    config.secret_token = '095f674153982a9ce59914b561f4522a'
    end

    class PagesController < ActionController::Base
    def index
    render :text => "Hello, world!"
    end
    end

    Application.routes.draw do
    get '/' => 'pages#index'
    end
    2 changes: 2 additions & 0 deletions config.ru
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    require './application'
    run Application