使用Sinatra运行rackup时出错

时间:2014-04-13 09:52:46

标签: ruby sinatra

我正在关注the Tuts+ Sinatra course,我收到了错误消息。这是我的代码:

config.ru

require "./app"

run App

app.rb

require "sinatra/base"

IMAGES [
    { title: "Utopia",      url: "http://www.techno-utopia.com/techno-utopia.jpg" },
    { title: "Alaska",      url: "http://www.cruisebrothers.com/images/Destinations/Alaska.jpg" },
    { title: "The Unknown", url: "http://www.tasospagakis.com/wp-content/uploads/2012/11/fear_of_the_unknown_by_ilhaman-d4cukmg1.jpg" }
]

class App < Sinatra::Base
    get "/images" do
        @images = IMAGES
        erb :images
    end

    get "/images/:index" do |index|
        @image = IMAGES[index]
    end

    get "/" do
        "Hello world!"
    end

    post "/" do
        "Hello world via POST!"
    end

    put "/" do
        "Hello world via PUT!"
    end

    delete "/" do
        "Goodbye world via DELETE!"
    end

    get "/hello/:first_name/?:last_name?" do |first, last|
        "Hello #{first} #{last}"
    end
 end

/views/images.erb

<h1>Images</h1>

<% @images.each do |image| %>
    <h2><%= image[:title] %></h2>
    <img src="<%= image[:url] %>">
<% end %>

运行rackup时出现错误:

Error

一如既往 - 非常感谢您提供的任何帮助!

1 个答案:

答案 0 :(得分:2)

你错过了=

IMAGES = [
    { title: "Utopia",      url: "http://www.techno-utopia.com/techno-utopia.jpg" },
    { title: "Alaska",      url: "http://www.cruisebrothers.com/images/Destinations/Alaska.jpg" },
    { title: "The Unknown", url: "http://www.tasospagakis.com/wp-content/uploads/2012/11/fear_of_the_unknown_by_ilhaman-d4cukmg1.jpg" }
] 

通过在变量名称和赋值运算符(=)的任一侧放置值来声明变量并赋值。 Source