Last active
May 21, 2018 12:03
-
-
Save saboyutaka/65d340b3863bc27fd1549ddb3676d0b2 to your computer and use it in GitHub Desktop.
ArrayとHashを表示させる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Fruits</h1> | |
<ul> | |
<% @fruits.each do |fruit| %> | |
<li><%= fruit %></li> | |
<% end %> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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