1
數組元素這是我app.rb
:獲得通過的關鍵
require 'sinatra'
COMICS = [
{
'name' => 'Test #1',
'code' => 'Link №1'
},
{
'name' => 'Test #2',
'code' => 'Test №2'
},
{
'name' => 'Test #3',
'code' => 'Test №3'
},
{
'name' => 'Test #4',
'code' => 'Test №4'
}
]
get '/' do
erb :index, :locals => { :comics => COMICS }
end
get '/single/:key' do
comic = COMICS[params['key']]
erb :single, :locals => { :comic => comic }
end
但是當我嘗試訪問:/single/0
比如我收到以下錯誤:
TypeError at /single/1
no implicit conversion of String into Integer