Skip to content

Instantly share code, notes, and snippets.

@nlharri

nlharri/app.rb Secret

Last active November 26, 2018 11:05
Show Gist options
  • Save nlharri/5ce357f60b3208aa04f359bf56559474 to your computer and use it in GitHub Desktop.
Save nlharri/5ce357f60b3208aa04f359bf56559474 to your computer and use it in GitHub Desktop.
Ruby Message Board App
require 'sinatra'
# Listen on all interfaces in the development environment
# This is needed when we run from Cloud 9 environment
# source: https://gist.github.com/jhabdas/5945768
set :bind, '0.0.0.0'
set :port, 8080
get '/' do
t_msg = [
{ nick: "Harri", msg: "Hello World!" },
{ nick: "Ioana", msg: "Buna dimineata" },
{ nick: "Alexandru", msg: "sunt fericit" }
]
erb :v_message, :layout => :l_main, :locals => {:t_msg => t_msg}
end
<!doctype html>
<html lang=en>
<head>
<link rel="stylesheet" type="text/css" href="/stylesheets/main.css">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<meta charset=utf-8>
<title>Message Board</title>
</head>
<body>
<div class="pageheader">
<h1>Message Board</h1>
</div>
<div class="speech-bubble">
<form action="/new" id="newmessage">
<p class="nick"><input type="text" placeholder="Nickname" name="nickname"></p>
<p class="message"><textarea placeholder="Message" name="message" form="newmessage"></textarea></p>
<p class="submit"><button class="submit" type="submit" form="newmessage" value="Submit">I say this!</button></p>
</form>
</div>
<%= yield %>
</body>
</html>
<% t_msg.each do |msg| %>
<div class="speech-bubble">
<p class="nick"><%= msg[:nick] %> says:</p>
<p class="message">&nbsp;&nbsp;&nbsp;"<%= msg[:msg] %>"</p>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment