Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Cleaning Up Our Code

Ralph Johnson
Ralph Johnson
10,408 Points

I gotta understand this, and I don't yet (fuzzy)

before_action :find_todo_list . I understand the "before_action" part. No problem.

But I can't recall what the colon is for, and it appears all over the code for this app (text in red, preceded by a colon). I get that in every case it's calling some method--but I don't remember what's special about these particular method calls being preceded by a colon. A scope issue? Global variable, maybe? Can't recall, and I obviously need to know it.

Can somebody refresh my memory?

4 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

This is called a symbol in Ruby. Why do we use them this way in Rails? There's probably an answer somewhere, but in general, like most things in Rails - that's the convention.

Ralph Johnson
Ralph Johnson
10,408 Points

Thanks for your quick response, Maciej -- I have to re-read some documentation on symbols.

I remember it from working with hashes, but that was just writing Ruby code.

In rails, things jump back and forth between files so often that my head is spinning trying to keep up with the cause-effect relationships. So much happens "behind the scenes." I wish the treehouse staff would spend one whole session simply explaining the file relationships that are created when you type "rails generate [scaffold, model, controller, etc]," and how those files relate to one another. It would make things easier to follow. Do you know if there's a resource where the rails file/directory structure is explained, say, in a block diagram?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

There is a more detailed online ebook (free to read as html, paid if you want a pdf or epub):

http://rails-4-0.railstutorial.org/book

Perhaps you will get some 'a-ha!' moments from it. The link above is the Rails 4.0 version (used in Odot) with RSpec. The newest edition uses newer Rails and different testing framework. There is also a book from Pragmatic Bookshelf which has some explanations on how things work behind the scenes.

Ralph Johnson
Ralph Johnson
10,408 Points

I started that rails tutorial a couple weeks ago and dropped it because mid-tutorial it shifted from Ruby 1.9.3 (and rails 3.something) to Ruby 2.0 and rails 4 --I wasn't even able to go back and revisit previous text because it had all been changed. Also got bogged down in Bitbucket and Heroku errors, encryption key errors, etc (delays that prevented me from learning very much about rails). I'm on a PC so rvm isn't an option without some workarounds. Finally just dumped it all and installed Ruby 2.0 and Rails 4. I'll revisit the rails tutorial later. Thanks for that suggestion, though.

Do you know the name of the book from Pragmatic Bookshelf? They have a video tutorial that looks like it would be just what I'm after, but I don't have the $180 to take it right now. Couldn't find many rails-specific books, but maybe I just don't know what title I'm looking for.

Thanks again for your help.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

It's "Agile Web Development with Rails 4". Also, if you're on PC, go from Windows to Linux as soon as possible. Rails development under Windows is very painful and there isn't much support and help online because there are very few people who use Windows for this. To make sure you don't screw up your Windows installation, go for virtual machine with VMWare Player. It's free. Linux distros are also free. I personally use and prefer Ubuntu - lots of help from other users available online. Ruby and Rails work faster and I can follow all tutorials that use Mac (which is 99.9% of them), because Linux and Mac share the same terminal commands. RVM works like a breeze. You can also use Treehouse's dedicated virtual machines, although I have no idea how they work and how to use them.

Ralph Johnson
Ralph Johnson
10,408 Points

Thanks once again for your help.

I have Ubuntu on my desktop machine but tried installing inside windows--that's resulted in a lot of system errors (in Ubuntu) that I don't know how to fix yet, and that's after going through a bunch of workarounds just to get it to install in the first place.

On the new (used) laptop I just bought, I installed Ubuntu in a new partition (which cut into my HD space quite a bit) and it installed without any errors. I tried the VM approach on the desktop machine (using Ubuntu on a USB stick) but it responds very slowly. I'd like to get the installation on my desktop working properly without re-partitioning the C drive, but it could take a while, and some research--some communication with users/experts online. I may end up going for the partitioned approach [sigh], and hope it doesn't mess with the Windows installation. Didn't seem to cause any problem with Windows on the laptop (though it does, now, boot to Ubuntu by default).

Thanks for responding, thanks for the book title, thanks for your patience with a newbie, and have a great day!

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You too. Wish you luck in your endeavors :)

Matthew Morris
Matthew Morris
11,321 Points

This was a long time ago, so you may have moved on, but Rails Tutorial now has a nice workspace already set up on cloud 9 which allows you to work in the exact same dev environment as the book and makes following along a breeze. I stopped around chapter 8 myself and decided to get a background with Treehouse before moving any further in the book, but it explains things very well and is a great resource for those able to follow along, which should be pretty much everyone now that the dev environment is consistent for all learners.