Last active
December 24, 2015 18:29
-
-
Save ryanmenzer/6843138 to your computer and use it in GitHub Desktop.
from "Rails the Sinatra Way", deaf grandma not speaking to me!
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
<div class="container"> | |
<h1>Deaf Grandma</h1> | |
<% if @grandma %> | |
<p>Grandma says: "<span id="grandma_says"><%= @grandma %></span>"</p> | |
<% end %> | |
<form action="/grandma" method="post"> | |
Say something to Grandma: | |
<br> | |
<input type="text" name="user_input"> | |
<input type="submit" value="Say it!"> | |
</form> | |
</div> |
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
class PagesController < ApplicationController | |
def index | |
@grandma = params[:grandma] | |
end | |
def show | |
input = params[:user_input] | |
if input == input.upcase && input != "" | |
@grandma = "NOT SINCE 1983!" | |
else | |
@grandma = "SPEAK UP, SONNY!" | |
end | |
render :index | |
end | |
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
LearningRails::Application.routes.draw do | |
get '/' => 'pages#index' | |
match '/grandma' => 'pages#show' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment