To Examples

Poem Example

Directions

  1. Create a new Rails project named EdgarAllenPoe.
  2. Generate a controller with the name Raven having the view show.
  3. Source code for the view Poem/app/views/raven/show.html.erb:
    <h1>Poem Example</h1>
    
    <p><%= @file_name %></p>
    
    <pre>
      <%= @poem %>
    </pre>
    
  4. Source code for the controller Poem/app/controllers/raven_controller.rb:
    class RavenController < ApplicationController
      def show
        @file_name = Rails.root.join 'app', 'assets', 'files', 'poem.txt'
        @poem = ""
    
        File.open(@file_name, "r") do |f|
          while line = f.gets
            @poem += line
          end
        end
      end
    
    end
    
    
  5. Source code for the stylesheet: Poem/app/assets/stylesheets/raven.scss:
    * { font: normal 150% Chiller;
        background-color: black;
        color: orange; }
    
  6. Copy the textfile poem.txt into Poem/app/assets/files/poem.txt.
  7. Localhost URL to view show:
    http://localhost:3000/raven/show