My First Rails App

Yay! My first rail app has been deployed! It’s a simple project manager application, and you can see it in action, and mess around with it (but don’t hack it, I didn’t escape all of the forms) here. I learned everything I needed to make this from PeepCode’s Meet Rails screencasts. In this 2 part series, you get guided step-by-step through the Ruby on Rails installation process. Once you’ve installed everything, you can start working on a rails app on your local computer. You can fully run it on your local computer– no need to buy server space until you’re ready to deploy an app to the world. You also get step-by-step instructions for how to make the project manager application I linked to above.

The PeepCode screencasts are $12 each and well worth the money, but you definitely need some programming experience in order to fully take advantage of them. I’d say a beginner to intermediate grasp of HTML and CSS is desirable. Additionally, you should have some programming experience. Without any prior web development and programming experience, you’d easily get lost and confused trying to follow along in these screencasts. That said, I highly recommend the PeepCode screencasts as a great place to begin learning all about Ruby on Rails. They start at square one and finish with a fully functional app.

The only thing missing from the screencasts was how to deploy your app onto a web server, but I suppose this varies depending on your hosting provider. As I said in an earlier post, I am using Rails Playground to host my site. I must say that their documentation on setting up your app is not the greatest. It may be outdated (last updated in 2008), it was hard and confusing for a beginner like myself to follow, and some of the steps I finally did take to setup my app were not even mentioned in this article. I used a different method.

Before I deployed my app, it was already running perfectly on my local computer. After starting up rails server, I could access my app by navigating to http://localhost:3000/ on my local computer. I was running Ruby 1.9.2 and Ruby on Rails 3.0.4 on my local computer. My Rails app used SQLite 3.7.5 for its database.

Here is what I had to do to setup my app at Rails Playground:

  1. Upload my Rails app folder to Rails Playground via FTP. Easy enough.
  2. Create a new subdomain on which my app would run. It’s simple to do this using cPanel.
  3. Change the document root path of the new subdomain to point to the “public” directory of the rails app I just uploaded. I also did this in cPanel, though I believe this can be done via SSH on the command line as something along the lines of (don’t quote me on this):
    ssh youraccount.com
    mv public_html public_html_bak
    ln -s ~/railsapp/public ~/public_html 
    
  4. On my local computer, I made a copy of /railsapp/db/development.sqlite3 and named this copy production.sqlite3. Then I uploaded this via FTP to the db folder. This step is necessary because on your local computer, your app is in the “development environment.” On the web server, your app is in the “production environment.” In the production environment, the app uses the database “production.sqlite3”. As such, we need to make a copy of our development database so that the app has a database that it can use on the web server. One thing I’m not clear on is how Rails “knows” that it’s in the production environment once on the server. Seems like magic, so I guess I shouldn’t be surprised.
  5. SSH into the server and navigate to your railsapp folder. Run “bundle install”, which will install all the gems that your app needs. If you don’t have permission to run this command, try running “bundle install --local”. A good SSH client if you don’t have one is PuTTY.
    ssh youraccount.com
    bundle install
    
  6. There may be some gems that are not available on your hosting provider’s servers. If this is the case, the bundle install will not be successfully completed, and you will have to notify support.
  7. View the finished product at your newly created subdomain!

As I understand it, my deployed rails app is running on Passenger. On my local computer, it was running on the WEBrick server, which is started by running the “rails server” command. I can’t tell the difference in using my app online vs. offline, which seems like a good thing.

The Rails Playground staff were very helpful in working through the problems I encountered deploying my first rails app. I communicated conveniently via the Rails Playground chatroom, which seems to be staffed 24/7. I was doing all of this at around 2:00 AM EST, so hopefully these guys are half way around the world in India (judging by their names, they probably were), rather than staying up all night. One of my gems would not install when I ran “bundle install”. Upon telling the staff this in chat, a staffer immediately updated Rails to the latest version on my server, after which, everything went smoothly. My only complaint is that I wish their support articles were more up-to-date, more beginner friendly, and more detailed. But with a chatroom full of staffers ready to help you, who needs any support articles? Aside from a couple 5 or 10 minute intervals when someone else was asking a question in the chat room, I had a monopoly on the two staffers’ attention. Perhaps this is a function of the time (2:00 AM EST), but if things are always this great, I’d be happy.

Ruby on Rails is pretty magical. You can create user and database models amazingly fastly, and most of the messy and annoying database code is abstracted away with the magic of Rails. I really like that all of the database related code you write is abstracted. This means that if you decide to switch from SQLite to MySQL, you hardly have to change a thing. On another note, the magic of pluralizations never ceases to amaze me. When I create a Person object in my Rails app, I can immediately start referring to “People” in my code. How did Rails know the plural automatically?? I’m guessing there’s an army of English majors behind the scenes serving up pluralizations on demand.

Leave a comment

Your email address will not be published. Required fields are marked *