Commit 0479c96
Changed files (5)
app
config
initializers
app/controllers/lines_controller.rb
@@ -0,0 +1,5 @@
+class LinesController < ApplicationController
+ def show
+ render text: Image.find(params[:id]).to_xml
+ end
+end
app/models/image.rb
@@ -0,0 +1,16 @@
+class Image
+ def self.find(id)
+ svg = Scale::SVG.new(width: "100%", height: "100%")
+ path = Scale::Path.new
+ path.move_to(x: 10, y: 10)
+ 10.times do |n|
+ path.horizontal(90, relative: true)
+ path.vertical(90, relative: true)
+ path.horizontal(10, relative: true)
+ end
+ path.close_path
+
+ svg.add(path)
+ svg
+ end
+end
app/views/home/index.html.erb
@@ -1,2 +1,5 @@
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
+
+<%= image_tag line_path(id: Time.now.to_i, format: :svg) %>
+
config/initializers/mime_types.rb
@@ -2,3 +2,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
+ Mime::Type.register "image/svg+xml", :svg
config/routes.rb
@@ -1,5 +1,6 @@
Rails.application.routes.draw do
root 'home#index'
+ resources :lines, only: [:show]
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".