Update: Week 2 of Learning Ruby

I’m currently in the middle of jumping head first into learning ruby on rails. If you told me that it’s only been two weeks since I decided to give the Ruby programming language another try (my first exposure to Rails was in November at a free Railsbridge workshop), I wouldn’t believe you.  For the most part I have utilized the resources that I mentioned in my previous post however, I am behind and ahead of my proposed schedule. I’m building but should probably balance that with some more reading.

InstallRails.com | The easiest way to install Rails on your computer :)

InstallRails.com | The easiest way to install Rails on your computer 🙂

Week 1

In Week 1, I got acquainted with Ruby and set up my development environment. I went through about half of TryRuby, did a lot of non-Ruby exercises on TreeHouse‘s Rails Development Track and did a handful of exercises from Learn Ruby the Hard Way (Free HTML book or  print version $20+). The most important thing I did was re-install Ruby and Rails. Here’s a step-by-step guides to setting up the Rails Environment: http://installrails.com/.

Progress: I finished a handful of Ruby exercises from LRTHW as well as a few Extra Credit problems from Treehouse and I converted one of my very first Java programs (a change calculator) into Ruby. View on GitHub

Challenges: During WRails Track | Treehouseeek 1 I was ready to shift my focus to more-so to Ruby than Ruby on Rails because I still hadn’t gotten to any actual Rails yet in Treehouse’s curriculum and I realized that Learn Ruby the Hard Way does not discuss Rails.  I’ve heard that it’s easier to jump into the Rails web application framework if you have a decent foundation in Ruby. However, there are differing opinions out there about exactly how much Ruby one should know before jumping into Rails. I finished the week eager to read up on Rails concepts such as Model-View-Controller architecture after beginning to tackle a tutorial for using Rails to create a blog app.

Week 2 – Debuggingdebugging

I was still working on the blog app and up until the beginning of week two, had been pretty good about debugging my own code (a.k.a fixing my own typos along the way). However, I ran into a mysterious problem (ha!), where information was being displayed 2x – correctly and then incorrectly in brackets.  I knew the problem had something to do with my view and I couldn’t quite figure out what. Luckily, I was able to get help from someone on the 4 week challenge discussion.

Weird, mysterious brackets “/
broken

Weird bracket display D:

Guess how many lines of code it took to fix this issue?

It took barely even one line of code to get rid of those brackets. I only had to remove TWO equal signs from my code to fix it!  In ERB (Embedded Ruby) files there’s difference between how information is displayed based on the embeddings you use:


 

I was able to fix my code by removing the = sign from <%= at the beginning of the each loops in my index.html.erb and show.html.erb files.


 

and here:


 

Result:

fixed

no more strange brackets!

What’s the difference between? = – % embeddings ?!




A note…

<% %> and <%- -%> are the same. Note however that <%= %> and <%= -%> are different: only the latter removes trailing whitespaces.

from RubyDocs

More Testing

After, fixing this issue I went back to Treehouse and started working on a todo list app. I started refactoring code in Ruby to make it DRYer (don’t repeat yourself) which is something I’ve dealt with in Java projects and even with CSS stylesheets. I also learned a little bit about using rspec to test a ruby app. You can write instructions to be executed and then run rspec to evaluate whether or not, for a given input the the expected output was achieved. If the expected output is achieved your app PASSED the test, if not the logic is off somewhere in your program. note: rspec tests are written in ruby and therefore are case-sensitive.

What’s next?

I am going to keep  working on my todo list and blog apps. I  want to start reading the Ruby on Rails tutorial book soon as it focuses on Rails and comes highly recommended.  Overall, I’m excited to continue learning more about Ruby/Rails. Ruby is a fun language to write in and I’ll definitely work on writing some more apps in pure Ruby and converting more of my Java projects into Ruby, at some point.

It’s not too late to join in!

Do you have some free time over the next month? If so, I encourage you to create your own version of the 4 week challenge and post updates here. You can follow my progress on GitHub.

Monica

Monica

Monica started Black Tech Diva to document her journey of learning more about programming and web development. If you'd like to chat, feel free to tweet her: @waterproofheart.

  • This is great! You’re progressing really fast. It took me a long time to get where you were. Also, I learned something from your post… I didn’t know about . However, I couldn’t find out what did. I googled erb, but it’s hard to google for symbols. Do you know what that does?

    • Thanks Jimmy for the encouragement!

  • Whoops it won’t let me type symbols in this reply box. I was asking about the less than sign, the percent sign, and then the minus sign… couldn’t figure out what that did in erb.

    • You’re right it’s super hard to find symbols in Google. I just updated the article to answer your question. The minus sign is used to remove leading whitespace. Here’s a link to some documentation on the different types of embeddings: http://api.rubyonrails.org/classes/ActionView/Base.htm.

  • Pingback: Journey to learn Ruby on Rails in 4 weeks! » Black Tech Diva()

  • Awesome job! ERB tags are fun and that I actually wasn’t aware of the use of “-“. Thanks for blogging about your experience in Rails