├── .gitignore ├── Gemfile ├── app ├── views │ └── quotes │ │ ├── index.html.erb │ │ ├── a_quote.html.erb │ │ └── quote.html.erb └── controllers │ └── quotes_controller.rb ├── db └── quotes │ └── 1.json ├── mini_migration.rb ├── config └── application.rb ├── sqlite_test.rb ├── Gemfile.lock ├── README.md ├── config.ru └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.db 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | gem 'rulers', :path => "../rulers" 3 | -------------------------------------------------------------------------------- /app/views/quotes/index.html.erb: -------------------------------------------------------------------------------- 1 | <% quotes.each do |q| %> 2 |
<%= q["quote"] %>
3 | <% end %> 4 | -------------------------------------------------------------------------------- /db/quotes/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "submitter": "Jeff", 3 | "quote": "A penny saved is a penny earned.", 4 | "attribution": "Ben Franklin" 5 | } 6 | -------------------------------------------------------------------------------- /app/views/quotes/a_quote.html.erb: -------------------------------------------------------------------------------- 1 |2 | There is nothing either good or bad but 3 | <%= noun %> makes it so. 4 |
5 | 6 |7 | Ruby version <%= RUBY_VERSION %> 8 |
9 | -------------------------------------------------------------------------------- /mini_migration.rb: -------------------------------------------------------------------------------- 1 | require "sqlite3" 2 | 3 | conn = SQLite3::Database.new "test.db" 4 | conn.execute <7 | Submitted by <%= obj["submitter"] %> 8 |
9 | 10 |11 | Viewing with user agent: <%= ua %> 12 |
13 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require "rulers" 2 | 3 | $LOAD_PATH << File.join(File.dirname(__FILE__), 4 | "..", "app", 5 | "controllers") 6 | 7 | module BestQuotes 8 | class Application < Rulers::Application 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /sqlite_test.rb: -------------------------------------------------------------------------------- 1 | require "sqlite3" 2 | require "rulers/sqlite_model" 3 | 4 | class MyTable < Rulers::Model::SQLite; end 5 | STDERR.puts MyTable.schema.inspect 6 | 7 | # Create row 8 | mt = MyTable.create "title" => "I saw it again!" 9 | mt["title"] = "I really did!" 10 | mt.save! 11 | 12 | mt2 = MyTable.find mt["id"] 13 | 14 | puts "Title: #{mt2["title"]}" 15 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: ../rulers 3 | specs: 4 | rulers (0.0.2) 5 | erubis 6 | multi_json 7 | rack 8 | sqlite3 9 | 10 | GEM 11 | remote: http://rubygems.org/ 12 | specs: 13 | erubis (2.7.0) 14 | multi_json (1.5.0) 15 | rack (1.4.1) 16 | sqlite3 (1.3.6) 17 | 18 | PLATFORMS 19 | ruby 20 | 21 | DEPENDENCIES 22 | rulers! 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Best Quotes 2 | 3 | This is the "Best Quotes" example application from the book 4 | "Rebuilding Rails" by Noah Gibbs. You can find the canonical branch 5 | of this framework at "http://github.com/noahgibbs/best_quotes". 6 | 7 | It really only exists to give Rulers something to serve up. 8 | 9 | The code is still free to use if you want to. I just don't know why 10 | you'd want to. 11 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | require './config/application' 2 | 3 | app = BestQuotes::Application.new 4 | 5 | use Rack::ContentType 6 | 7 | app.route do 8 | match "", "quotes#index" 9 | match "sub-app", 10 | proc { [200, {}, ["Hello, sub-app!"]] } 11 | 12 | # default routes 13 | match ":controller/:id/:action" 14 | match ":controller/:id", 15 | :default => { "action" => "show" } 16 | match ":controller", 17 | :default => { "action" => "index" } 18 | end 19 | 20 | run app 21 | -------------------------------------------------------------------------------- /app/controllers/quotes_controller.rb: -------------------------------------------------------------------------------- 1 | class QuotesController < Rulers::Controller 2 | def a_quote 3 | render :a_quote, :noun => :winking 4 | end 5 | 6 | def quote_1 7 | quote_1 = FileModel.find(1) 8 | render :quote, :obj => quote_1 9 | end 10 | 11 | def index 12 | quotes = FileModel.all 13 | render :index, :quotes => quotes 14 | end 15 | 16 | def show 17 | quote = FileModel.find(params["id"]) 18 | ua = request.user_agent 19 | render_response :quote, :obj => quote, :ua => ua 20 | end 21 | 22 | def new_quote 23 | attrs = { 24 | "submitter" => "web user", 25 | "quote" => "A picture is worth a thousand pixels.", 26 | "attribution" => "Me" 27 | } 28 | m = FileModel.create attrs 29 | render :quote, :obj => m 30 | end 31 | 32 | def post_test 33 | raise "NOT A POST!" unless env["REQUEST_METHOD"] == "POST" 34 | 35 | "Params: #{request.params.inspect}" 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Noah Gibbs 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------