Rails Intro #1: A data management application in five easy steps

I am planning to write a series of articles on how to get started with Ruby on Rails. One of the remarkable things about Rails is that it lets you get up and running very quickly. Here is what you need to do to get your first application up and running.

Before you start, you need to install Ruby on Rails: On Macs, Rails is already available and you can type the following commands in a normal terminal window. On Windows, you can get everything you need from InstantRails. Once you have unpacked InstantRails to a subfolder, start the “InstantRails.exe”. From the GUI that comes up, click the “I” button in the top left corner and select “Rails Applications” -> “Open Ruby Console Window” from the menu. The following commands should be typed in the command line window that shows up.

  1. rails blogdemo
  2. cd blogdemo
  3. (Optional: Look at how generators work – read the documentation that is printed) ruby script/generate
  4. (Optional: Look at how generators work – read the documentation that is printed) ruby script/generate scaffold
  5. ruby script/generate scaffold article title:string author:string content:text
  6. (Optional: Look for the documentation on the “rake” command) rake --tasks
  7. (Optional: Look for the documentation on the “rake” command) rake -T db
  8. rake db:create:all
  9. rake db:migrate
  10. (Optional: Load generated test data into the database) rake db:fixtures:load
  11. (Optional: Run the generated tests) rake test
  12. ruby script/server
  13. You should now be able to view your wonderful application at http://localhost:3000/articles
  14. Be sure to read the documentation at http://localhost:3000/ as well

Enjoy your first rails application!

Generated article list

If you find the results satisfying, you should start by exploring the directory structure of the files generated by Rails. In my next article, I will tell you how to generate more advanced data structures, so that we can add comments to our blog articles. (Still to come future: How to setup a server and deploy to it, tips on working with your code, exploring the rails structure, AJAX, and RSS feeds)

About Johannes Brodwall

Johannes is Principal Software Engineer in SopraSteria. In his spare time he likes to coach teams and developers on better coding, collaboration, planning and product understanding.
This entry was posted in Ruby-on-Rails. Bookmark the permalink.
  • HSA72

    Thanks.

    I will follow your articles on Rails!

  • HSA72

    Thanks.

    I will follow your articles on Rails!

  • Daniel

    Mac OSX Leopard has Rails pre-installed, just like you said. But it's an old version, so your tutorial doesn't work out of the box.

    Just run “sudo gem update rails”, type your password, and answer yes to all the questions to get going.

    This was a great and compact tutorial by the way. Thanks.

  • Daniel

    Mac OSX Leopard has Rails pre-installed, just like you said. But it’s an old version, so your tutorial doesn’t work out of the box.

    Just run “sudo gem update rails”, type your password, and answer yes to all the questions to get going.

    This was a great and compact tutorial by the way. Thanks.

  • Any ideas about what to do if you already have Apache running on your computer?

  • Apache will prevent InstantRails from starting, but the rest of the tutorial is actually not dependent on this.

  • sjbrodwall

    Any ideas about what to do if you already have Apache running on your computer?

  • Apache will prevent InstantRails from starting, but the rest of the tutorial is actually not dependent on this.