views:

568

answers:

7

I'm a compsci student who wants to get learn a little about web development -- I learn best by doing. I know basic html/css/php/javascript/xml, but since Ruby is one of my favourite scripting languages, I figured I'd learn Ruby on Rails.

I'd like to build a basic website for a friend's club at school that just provides information about their organization and services they offer, and have an admin panel on it that contains a very basic inventory system (item, number in inventory, cost -- that's it) in order to learn Ruby on Rails. I'll be hosting it on a computer on campus -- so I don't have to worry about hosting.

This might sound a little silly, but as someone who's never built a website themselves, I was wondering how exactly one goes about it with rails -- like, how do I make a basic layout for the main part of the site -- with things like "Home, About Us, Services, Contact, Club Executive" along the top? Do I have to make it in html and put it in the "view" section? The tutorials I've read on rails (Getting Started With Rails) actually make the basic inventory system seem easy, compared to this part, using a lot of the built in functionality of Rails and scaffolding. The Rails documentation is a tad bit confusing.

+1  A: 

You should read about Model-View-Controller architecture if you have not yet done so, as it is the basis for most web frameworks including Ruby on Rails.

Alan Haggai Alavi
+4  A: 

The "official" Rails book is quite good if you want to start building Rails applications. link

But actually is something like this:

  1. Create the rails app using rails applicationname
  2. Create the controllers. It seesm that for you one controller is actually enough, name it for example main: ruby script/generate controller main
  3. Now you have a controller in app/controllers, called main_controller.rb. Here you can insert the actions you want this controller to respond. If you don't want the controller to do anything just show the view, then leave the method empty.

    class Main < ActionPack::Controllers
    def index
    end
    def about
    end
    def contact
    end
    (...)
    end
    
  4. Now you got a controller that will respond to index, about and contact.

  5. Create the views for this controller in app/views/main/index.erb (and others, like about.erb)
  6. You can simply use HTML if you want
  7. Alternatively you can use a layout, that you have to define in app/views/layouts/main.rhtml In this layout use HTML, but wherewer you want to include the view, write <%= yield %> Example:

    <HTML>
    <BODY>
    <%= yield %>
    </BODY>
    </HTML>
    
  8. You can include this layout in the controller by writing layout :main in the class (before the method declarations)

  9. Now if you run ruby script/server in the root of the app you can access the pages you've created. They will be static of course, but this might get you going. You have to add models and some logic to your controllers to advance. I advice you to check the book I linked if you're interested in more, or check the alternatives of rails like merb (http://merbivore.org) which has some nice features and is usually faster, but lacks the maturity of rails.
SztupY
A: 

It sounds to me like this site might not be the best way to learn Ruby on Rails. Rails is really great for CRUD applications (applications which allow users to Create, Read, Update, and Delete records in a database). Since your site looks to be all static pages except for the "Contact Us" section (which I'm assuming is a form that sends an email with some kind of confirmation page), you're actually going to find yourself kind of fighting against "The Rails Way."

Ideally in a situation like this, you could just throw all of your static pages into the public/ directory and make a quick Rails scaffold for the "Contact Us" page.

But by doing that, you won't end up with a finished project that resembles a typical Ruby on Rails application, and in the worst case, you might find yourself having to "unlearn" or at least "relearn" a lot of the aspects of Rails programming.

I think building a CRUD application with several resources (the canonical "Rails blog in 15 minutes" is a great start. You'll learn more by practicing Rails conventions and seeing the kind of workflow and application that really allows Rails to shine.

Then when it comes time to build another mostly-static website, you'll know exactly what you'll need to do to go about it.

My 2 cents, anyway.

Bryan Woods
A: 

Start off with Mephisto. It will give a framework to achieve your goal rather fast... otherwise you may simply flounder learning the gazillion things involved in creating the rails website.

Ryan Oberoi
A: 

With a simple site, I'd go for a Ruby micro-framework. The three I like are: Sinatra, Ramaze or _why's 4k Camping (get the one with the bugs fixed). RoR would be overkill.

Dave Everitt
A: 

I must recommend Ramaze. If you already know Ruby, but don't know Rails yet, Ramaze is better suited to you because it is "closer to home" as far as Ramaze apps being pure(r) Ruby.

For your DB access, you get a choice of ORMs. Sequel is most popular among Ramazers, but there's also DataMapper and M4DBI.

As Alan Alavi already said: You should familiarize yourself with MVC, but that can be done simply by diving in and getting your hands dirty. Try out the todolist tutorial, as it covers many of the core aspects and processes involved in building web apps.

Pistos
A: 

I picked up the book "Agile Web Development with Rails", and it's excellent. It goes through building an online grocery cart.

Robyn Smith