So I wanted to start this weeks' testing explorations taking another look at how to use pry as I'm working with this server stuff. I used it once before but now would really like to see how I can monitor my 'inputs' etc and exactly where to inturrupt the server to get these answers.
I took a stab at inserting binding.pry in different places in my server, and got some confusing results.
example;
require "sinatra"
require "pry"
get "/items" do
@items = ["00786", "88693", "66793", '77385']
erb :index
end
get "/items/:item_name" do
@item_name = params[:item_name]
erb :show
end
binding.pry
post "/items" do
redirect "/items"
end
..so here I'm putting it after the second get. And I get these results once I start the server;
ruby server.rb
== Sinatra (v2.0.4) has taken the stage on 4567 for development with backup from Puma
Puma starting in single mode...
* Version 3.11.0 (ruby 2.3.3-p222), codename: Love Song
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567
Use Ctrl-C to stop
::1 - - [30/Nov/2018:12:25:12 -0500] "GET /items HTTP/1.1" 200 713 0.0176
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2018-11-30 12:25:26 -0500 ===
- Goodbye!
== Sinatra has ended his set (crowd applauds)
➜ todo_list git:(master) ✗ ruby server.rb
From: /Users/lesliewilson/marlboro_rails/todo_list/server.rb @ line 18 :
13: get "/items/:item_name" do
14: @item_name = params[:item_name]
15: erb :show
16: end
17:
=> 18: binding.pry
19:
20: post "/items" do
21: redirect "/items"
22: end
23:
Ok, fine. But when I go back to my form and try to submit something;
<!DOCTYPE html>
<html>
<head>
<title>Basic HTML Page</title>
<link rel="stylesheet" href="home.css">
</head>
<body>
<h1>index item list for server</h1>
<ul>
<% @items.each do |item| %>
<li>
<a href="/items/<%= item %>"><%= item %></a>
</li>
<% end %>
</ul>