Code-along and lab solutions
The following is the complete code by file for the Github repository: github.com/entr451-spring2026/web-apps/
Rails.application.routes.draw do
# resources "tacos"
get("/tacos", :controller => "tacos", :action => "index")
# resources "dice"
get("/dice", :controller => "dice", :action => "index")
# resources "cards"
get("/cards", :controller => "cards", :action => "index")
# resources "companies"
get("/companies", :controller => "companies", :action => "index")
# resources "contacts"
get("/contacts", :controller => "contacts", :action => "index")
end<%
fillings = ["Carnitas", "Al Pastor", "Steak", "Fish", "Ground Beef"]
%>
<h1>I love tacos!</h1>
<p>There are so many kinds of tacos!</p>
<ul>
<% for filling in fillings %>
<li><%= filling %></li>
<% end %>
</ul>
<p>Currently, there are <%= fillings.count %> kinds of tacos.</p><%
die1 = rand(1..6)
die2 = rand(1..6)
total = die1 + die2
%>
<h1>Roll the dice</h1>
<p>
<img src="/images/dice/<%= die1 %>.svg">
<img src="/images/dice/<%= die2 %>.svg">
</p>
<p>
The total is <%= total %>
</p>
<p>
<a href="/dice">Roll Again!</a>
</p><%
ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, "jack", "queen", "king", "ace"]
suits = ["clubs", "diamonds", "hearts", "spades"]
deck = []
for rank in ranks
for suit in suits
deck << "#{rank}_of_#{suit}"
end
end
shuffled_deck = deck.shuffle
hand = shuffled_deck[0,5]
%>
<h1>Welcome to the ENTR-451 Casino!</h1>
<p>
<% for card in hand %>
<img src="/images/cards/<%= card %>.svg">
<% end %>
</p>
<p>
<a href="/cards">Deal Again!</a>
</p><%
companies = Company.all
%>
<h1>Companies</h1>
<ul>
<% for company in companies %>
<li><%= company["name"] %></li>
<% end %>
</ul><%
contacts = Contact.all
%>
<h1>Contacts</h1>
<ul>
<% for contact in contacts %>
<% company = Company.find_by({ "id" => contact["company_id"] }) %>
<li>
<%= contact["first_name"] %> <%= contact["last_name"] %> @ <%= company["name"] %>
</li>
<% end %>
</ul>