Skip to content

Instantly share code, notes, and snippets.

@emmapersky
Created November 22, 2010 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmapersky/710431 to your computer and use it in GitHub Desktop.
Save emmapersky/710431 to your computer and use it in GitHub Desktop.
GDI Ruby. Class 3. Classes
require 'rubygems'
require 'sinatra'
class Animal
attr_accessor :name
def initialize(name)
@name = name
end
def about
"#{@name} is urrrrrr?"
end
end
get '/' do
erb :index
end
post '/animal' do
@animal = Animal.new(params[:name])
erb :about
end
__END__
@@ layout
<html>
<head>
<title>Animals!</title>
</head>
<body>
<%= yield %>
</body>
</html>
@@ index
<h3>Create an animal</h3>
<form method='post' action='/animal'>
<label for='name'>name</label><input type='text' name='name' /><br />
<input type='submit' />
</form>
<hr />
@@ about
<h3>About your animal: <%= @animal.about %></h3>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment