Good news - I am now officially a graduate of the Flatiron School class of RUBY-005! Hurray!
Can you pick me out of the crowd?
Now that I have some free time, I can finally update you on the progress of my Hobo Name Generator, which is now live (and has been for several weeks but sssh, don’t tell anybody)! You can view the complete code on my GitHub account, but first I’d like to review some highlights of various technical aspects of the project that caused me some amount of confusion. (If you’d like to read my original blog post on this topic, you can do so right here)
First, I changed the structure of the model altogether. I now only want to add the user’s name to a random hobo-esque adjective, so this is the new/current structure of the model:
require 'sinatra' class HoboGenerator attr_accessor :your_first_name, :hobo_name def initialize(your_first_name) @your_first_name = your_first_name end def hobo_name return ["Old Crankin' ","Young Skippin' ","Stinky ","Stabby ","Beefy ","Snaggletooth ", "Fancy ", "Slick ", "Wheezy ","Mudpie ","Filthy ","Whiskey ","Tin Can ","Soup-Spoon ","Bilgewater ","Bugeye ", "Surly ","Twitchy ","Rickety ","Shoeless ","Creaky ", "Sweet Geechin' "].sample + @your_first_name end end
Next, in app.rb, I defined the routes, which was the hardest part for me to figure out:
require_relative 'config/environment' require 'sinatra' class App < Sinatra::Base get '/' do erb :'hobo_generator' end post '/new' do erb :'new' end get '/new' do @name = params[:firstname] @new_name = HoboGenerator.new(@name).hobo_name erb :'new' end end
The trickiest part for me was learning about exactly what “get” and “post” meant (this was about a month ago, so don’t worry, I know better now!). I had been looking at the code of a similar project done by a classmate, whose code was almost identical to mine in structure, but only had one “get” and one “post” request. No matter how I arranged my code, even seemingly copying it exactly, I could not get Sinatra to understand this ditty!
Finally, I rearranged my code in a way that made sense to me, and it worked! Three cheers, hurray! I knew it made sense that I would need another get request, and I was right!
It was definitely helpful to look at other people’s code in order to figure out how all the moving parts in Sinatra work together, but in the end, I learned that one person’s code is another person’s Sinatra error page, and it’s best to trust your instincts!
I know my Hobo Name Generator app is super simple, but I’d really like to utilize an AJAX request to have it all on one page (mostly so I can learn more about how AJAX requests work). I’d also like to pretty up the page a bit with some of my own original hobo-themed art, and figure out how I want to integrate the Hobo Name Generator into the Freewheel webcomic site.