Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion theweb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
enable :sessions

get '/' do
erb :dashboard
about_me = Array["a human being", "female", "a programmer", "fun"]
random_about_me_choice = rand(about_me.length)
@about_me_choise = about_me[random_about_me_choice]
erb :about
end

post '/number' do
Expand All @@ -16,3 +19,10 @@
@the_number = rand(number_as_string)
erb :number
end

get '/about' do
about_me = Array["a human being", "female", "a programmer", "fun"]
random_about_me_choice = rand(about_me.length)
@about_me_choise = about_me[random_about_me_choice]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a fun ruby way to do this:

First, no need to use "Array", you could do

about_me = ["a human being", "female", "a programmer", "fun"]

Then, to randomly pick something out, you can reduce that to:

@about_me_choice = ["a human being", "female", "a programmer", "fun"].sample

#sample will shuffle the array and pick the first item. fun!

erb :about
end
3 changes: 3 additions & 0 deletions views/about.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>ABOUT ME</h1>
<h2>I am <%= @about_me_choise %></h2>

3 changes: 3 additions & 0 deletions views/dashboard.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
<input type="text" id="number" name="number"/>
<input type="submit" class="btn btn-large btn-primary" value="View Number"/>
</form>
<form method="GET" action="/about">
<label for="about">about dharini</label>
</form>