Skip to content

Instantly share code, notes, and snippets.

@saboyutaka
Last active May 21, 2018 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saboyutaka/65d340b3863bc27fd1549ddb3676d0b2 to your computer and use it in GitHub Desktop.
Save saboyutaka/65d340b3863bc27fd1549ddb3676d0b2 to your computer and use it in GitHub Desktop.
ArrayとHashを表示させる
require 'sinatra'
require 'sinatra/reloader'
set :public_folder, File.dirname(__FILE__) + '/public'
get '/' do
@title = 'hoge'
erb :index
end
get '/hello' do
erb :hello
end
get '/fruits' do
@fruits = ['Apple', 'Banana', 'Lemon', 'Meron', 'Strawberry']
erb :fruits
end
get '/info' do
# @infos = db.query("SELECT * From infos")
@infos = [{
name: 'saboyuta',
age: 30,
favorites: ['音楽', 'コーヒー', 'プログラミング']
},{
name: 'gakeo',
age: 27,
favorites: ['Pairs', 'Tapple', 'Tinder']
}]
erb :info
end
<h1>Fruits</h1>
<ul>
<% @fruits.each do |fruit| %>
<li><%= fruit %></li>
<% end %>
</ul>
<h1>Info</h1>
<% @infos.each do |info| %>
<p>名前は、<%= info[:name] %></p>
<p>年齢は、<%= info[:age] %></p>
<ul>
<% info[:favorites].each do |favorite| %>
<li> <%= favorite %></li>
<% end %>
</ul>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment