Join Kevin Skoglund for an in-depth discussion in this video Text editor, part of Ruby on Rails 3 Essential Training.
We're almost done with all the installations that we need to be able to develop with Ruby on Rails. The last thing is I just want to make sure that you have a good text editor that you can use for writing your code. Now, Mac OS X comes with a very simple text editor called TextEdit. And you may also have some word processing programs like Microsoft Word or OpenOffice or Pages. None of those are going to be suitable for developing with code. Instead we need something that really is designed to not just be a text editor but a code editor. There are a few key features that we need to look for. The first is you want something that does code coloring or syntax highlighting.
The second key feature is that you won't be able to easily navigate the whole project at once. That's very important in Rails because a lot of things are going to be broken up between different files and we're going to have things calling from one file to another file. So we're going to be bouncing back and forth, making one change here, flipping back over, making another change to another file here. So, we want something that's like a project window or the ability to have open file tabs that will very easily allow us to flip back and forth between different pages. We don't want to have to go back to Mac OS X's Finder and reopen another page from there.
You also want to have something that's really good for search and replace. You want to be able to search your entire project and find every time that you've called a certain method name or used a certain variable. Then last, auto-pairing of brackets, parentheses, and quotes. By far the most common mistake that people make in programming is forgetting to close a parentheses or a quotation mark. If you have a program that is auto- pairing for you, then as soon as you type the first open parentheses, it types the second open parentheses at the same time. When you keep typing, it types between them. That way you always make sure that you have both the open and the closed parentheses that are automatically paired.
There are also a couple of preferred features that I think are really nice. One is just a very simple auto-indent so that you don't have to keep hitting Tab to indent your code every time. It will just automatically indent to the right spot. The second is code completion. You type a few characters, you hit a magic key, and it says "Oh! I know what you're trying to type," and it will type a lot of good for you. It'll save you quite a few keystrokes, if you have something that will do code completion for you. And then last, to be able to customize the color of your document to change not only the document and the background color, but the actual syntax coloring as well.
A lot of texts are simply referred to that as being themes. And we've gotten to the point now where most code editors offer all of these features. So how do you choose which one? Well, the one I'm going to recommend most strongly to you is TextMate. That's what I use and I love it. And it's most popular in the Rails community. The Rails community as a whole has really embraced TextMate. It has excellent features and it also has a good price. It's a free 30-day trial, and it's only about $50 when you finally decide to buy it, at least at the time that I'm recording this. Now, there are some other editors and IDEs out there. IDE stands for Integrated Development Environment, and there are some people who swear by these and really like them better than TextMate.
So, you certainly can give them a try, RubyMine, RadRails, Eclipse, Netbeans, Komodo, Coda, MacVim and BBEdit. Some of those like Eclipse and Netbeans have existed before there was Rails, and there are some developers who have a Java background, let's say, who really like Netbeans. So if you do, then stick with it. You can certainly use that for Ruby on Rails as well. But we're going to be using TextMate. That's what I'm going to show you how to use. If you don't have a preference between these, I recommend that you try it first because it's a really great text editor. To install TextMate, we just need to go to the Macromates web site.
That's macromates.com, and their flagship product is TextMate. There is all sorts of information here about the features of TextMate, how to use them, frequently asked questions, you can really surf their site to get the most out of TextMate. But what we're going to focus on right now are these download links. There is download a free 30-day trial or buy a copy and get a license key. Either way, we need to download it first and then you can buy the license key and add that to your download. So, I'll tell Firefox to save that to my desktop. There it is. I can now close this window, and double-click on that.
It will launch the disk image. And then we just need to drag TextMate into this alias for Applications folder that they gave us. That will copy over. When it's done, we'll just double-click on Applications and we'll see here it is, inside our Applications folder. I'll drag a copy of that to my dock, so we have easy access to it in the future. Now I can close up these windows and let's open up TextMate. It says, "Are you sure you want to open it because I see you downloaded this from the Internet?" We do. Now when it launches, you can see I get a couple of windows. First is, do you want to register it? Well, if we have a license key, this is where we would enter it, but I don't yet so I'm going to type in Later.
And then there is this other window back here, Enhanced Terminal Usage. Now you can read to its full description, but essentially what this does, this allows us to install a program to the command line where we can type mate and it will then launch whatever we want inside TextMate. It's a very handy feature. We can pick where we're going to install it. I'm going to say go ahead and install it in /usr/bin. That's fine. Now what it's doing is creating a symlink for us to be able to do that. Symlink is like an alias. So we'll save that and now let me show you what it does. If we go to our Terminal, now for example, we saw that before I had this file called bash profile that we edited, well, now I can say mate .bash_profile and it pops it open inside TextMate. So there it is.
Now I can edit it there, just like a normal file. So it's very handy and you can do it on a folder to actually open up an entire folder of files and be able to work with those as well. As I said, you can go to the TextMate website to find out all the details about how to get the most out of it. But there is one thing that I want us to do right off the bat, which is from the View menu, that's picking the Gutter to show the line numbers. So that one now shows the line numbers here. That way if we get an error on line 7, we'll be able to very quickly and easily find that error on line 7 in our code. That's a really important feature to have turned on. So that's it.
Now we have all the parts that we need on the backend and we know that we have a good text editor to work with. We're ready to get started developing in Ruby on Rails.
- Understanding MVC (Model View Controller ) architecture
- Routing browser requests through the framework
- Responding to requests with dynamic content
- Defining associations and database relationships
- Creating, reading, updating and deleting records
- Working with forms
- Validating form data
- Reviewing built-in security features
- Authenticating users and managing user access
- Debugging and error handling