Created
November 22, 2010 18:51
-
-
Save emmapersky/710431 to your computer and use it in GitHub Desktop.
GDI Ruby. Class 3. Classes
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
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