I worked with server stuff this week. practiced using ERB, Embedded Ruby and made (picture attached) by creating the following files:
Index.erb;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Veggie Recipe Printer</title>
</head>
<body>
<h1>Veggie Recipie Printer</h1>
<ul>
<% @ingredients.each do |ingredient| %>
<li>
<a href= "/ingredients/<%= ingredient %>"><%= ingredient %></a>
</li>
<% end %>
</ul>
<ol>
<% @directions.each do |direction| %>
<li>
<a href = "/directions/<%= direction %>"><%= direction %></a>
</li>
<% end %>
</ol>
</body>
</html>
...To run the whole thing you can pull file down from github here: https://github.com/LeslieWilson/marlboro_rails its a file called 'ordered and unordered lists through server'.
I wasn't actually sure what an ordered list was vs an unordered one so had to read *this article *.
Did more with this, added another variable 'reviews'
reviews =
[{username:"larisa","leslie","nate"}, {ratings:1,2,3}, {review:"that sucked","so tasty","goddamit my stomach hurts dude"}]
get '/' do
@name = recipe[:name]
@ingredients = recipe[:ingredients]
@directions = recipe[:directions]
@usernames = reviews[:usernames]
@review = reviews[:review]
@ratings = reviews[:ratings]
erb :index
end
tried to work with it here:
<h2> Reviews </h2>
<% @usernames.each do |username| %>
<% @ratings.each do |rating| %>
<li>
<a href = "/usernames/<%= username %>"><%= username %> </a>
<a href = "/ratings/<%= rating %>"><%= rating %></a>
</li>
<% end %>
<% end %>
I was trying to get the names to show up next to the ratings... kept looking like this unfortunately and I kind of gave up after a while. But good to fidget with different kinds of hash organizations.
Reviews
larisa 1
2 3
leslie 1
2 3
nate 1
2 3
...yeah so that wasn't correct. Decided to move on.
So I am trying to make my own app and am having a hard time understanding where to plug the wires in so all these files can talk to each other and result in a webpage I can see. I've completed some simple web pages through sinatra but am using another template that is 'partially' filled in and a few things are different about it and I'm super puzzled.
right now I'm just trying to let a link appear and can't even do that. Am trying to make 'routes' like this;
get "/teams" do
@league = League.new
@name = ROSTER[:name]
"<h1>The LACKP Homepage<h1>"
erb :index
end
get "/" do
@name = params[:name]
erb :layout
end
and you need to call it in like 3 other different places for it to render, so far very confused because it doesn't like the @name =ROSTER..etc, for reasons I can't explain very well here. Basically having issues with naming variables will talk to nate and try again later today.
So working from the files this course gave me was confusing. They sort of give you 60% of what you need but it always looks different, and they throw it at you without much of an explanation of whats there. I am having nate strip away an example to the bare bones and just sort of trying to understand the basics before moving forward. There are apparently a million different things that make the server connect with everything else and it's getting confusing.
last modified | size | ||
Screen_Shot_2018-11-24_at_1.05.51_PM.png | Wed Dec 04 2024 06:54 pm | 339K |