"Tex" has one more "x" than you thinkSo, you ask, "how many x's are there in Tex?" Funny you asked. We used to play a game in college, someone would ask that, and I would say "one more than you think."Fun game. Let's try to code that. Whoa! How does that work? I'll tell you. No matter how many x's you put, Ruby will say one more. Ruby code
This is as simple as code gets. We call this if/elsif/else/end. Ruby eats structures like this for breakfast, lunch and dinner. No problem.
This is great structure. See how well it reads? Clear, right? We do one thing between "if" and "end," and the possibilities are almost infinite. My code has "ifs" nested inside each other, so the inner "ifs" are only checked if the first "if" is true. I check if you said anything, and only then do I respond. I see if you gave me a number, and only then do I check that it's in the range I'm looking for. (Ruby will get angry and bark at me if I ask it if something that's not a number is negative. She thinks it's a stupid question. I can't really disagree.) And I have a special place to respond to text in the "else." Else is like a catchall. Rails codeThat's a very interesting system, you say, but how does Ruby get into the web page? Excellent question. Remember Ruby's magic skateboard? It's Rails embedded in HTML.
Rails allows Ruby to collect your input and take it to the controller as parameter a_number. (The controller has all the Ruby code above. It sets the values of @number and @texxx so Rails can put them in your HTML.) Notice that this is Ruby code, but the code is encapsulated in <% %>. That structure tells the web server to use Rails. |