Monthly Archives: January 2008

Rails intro #2: One-to-many relationships

In my last article, I showed you how to get started with your Rails application. The result of the simple commands, rails blogdemo; cd blogdemo; ruby script/generate scaffold article title:string author:string content:text; rake db:migrate; ruby script/server was that you had your own simple blog up and running. The blog support articles each of which have a title, an author, and text content. This initial model was generated for us with no editing on our part.

In this second article, I will expand the blog to allow comments to our articles. This will require us to get our hands a bit more dirty with the Rails code, but it won’t be too bad. And even better: If you complete the instructions in this article, you can call yourself a Rails programmer!

Are you ready to dive in head first?

(more…)

Posted in Ruby-on-Rails | 4 Comments

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)

Posted in Ruby-on-Rails | 8 Comments