Skip to content

Instantly share code, notes, and snippets.

@jacobbednarz
Last active December 10, 2015 07:58
Show Gist options
  • Save jacobbednarz/00279c2749e202a82d6d to your computer and use it in GitHub Desktop.
Save jacobbednarz/00279c2749e202a82d6d to your computer and use it in GitHub Desktop.
require 'sinatra/base'
IMAGES = [
{ title: "matrix", url: "http://i0.kym-cdn.com/entries/icons/original/000/009/889/Morpheus2.jpg" },
{ title: "google", url: "http://i0.kym-cdn.com/news_feeds/icons/original/000/006/501/google-search.jpg" },
{ title: "skywalking", url: "http://i2.kym-cdn.com/photos/images/newsfeed/000/295/090/9de.jpg" }
]
class App < Sinatra::Base
get '/images' do
@images = IMAGES
end
get '/images/:index' do |index|
@image = IMAGE[index]
end
end
macbookpro: ~/code/sinatra-app
→ ls -la
total 16
drwxr-xr-x 4 jacob staff 136 29 Dec 15:36 .
drwxr-xr-x 12 jacob staff 408 29 Dec 15:10 ..
-rw-r--r-- 1 jacob staff 491 29 Dec 16:06 app.rb
-rw-r--r-- 1 jacob staff 25 29 Dec 15:14 config.ru
macbookpro: ~/code/sinatra-app
→ rackup
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require': ./app.rb:4: odd number list for Hash (SyntaxError)
{ title: "matrix", url: "http://i0.kym...
^
./app.rb:4: syntax error, unexpected ':', expecting '}'
{ title: "matrix", url: "http://i0.kym...
^
./app.rb:4: syntax error, unexpected ',', expecting $end
{ title: "matrix", url: "http://i0.kym-cdn.com/e...
^
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
from /Users/jacob/code/sinatra-app/config.ru:2
from /Users/jacob/.rvm/gems/ruby-1.9.2-p320/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /Users/jacob/.rvm/gems/ruby-1.9.2-p320/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /Users/jacob/code/sinatra-app/config.ru:1:in `new'
from /Users/jacob/code/sinatra-app/config.ru:1
macbookpro: ~/code/sinatra-app
→ ruby -rubygems app.rb
/Users/jacob/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- sinatra (LoadError)
from /Users/jacob/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from app.rb:1:in `<main>'
@jonahoffline
Copy link

Hey, here is the working version:
https://gist.github.com/4405233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment