views:

412

answers:

5

I'm just learning Ruby on Rails. I've read a few books, I've watched lots of Railscasts, I've looked at some examples.

However, when working on my first serious project with Rails, I've gotten hung up on how to properly implement some very basic web site features that most tutorials I've seen lack.

For instance: Navigation menus. Lots of tutorials on how to make a static one, but what about dynamic? If I want to make a navigation bar that's different across pages, how would I go about doing that?

I think that the best way to learn things like this is by seeing example code. Are there any good open sourced sites in RoR? Any example code that I can check out?

I guess my question really results to using MVC. The basic idea is really basic, and I understand that. But it seems that most applications have each part completely separate from each other... what if I want to, say, combine data from two models to display on the same page? To take the example I posed, if I have a NavModel and a PageModel, can my PageController access both models? I guess I'd assumed that a PageController can only access a PageModel, and none other. All examples I've seen seem to operate this way...is that a faulty assumption?

Or am I totally missing the point, and is that 'doing it wrong?'

+2  A: 

Open Source Rails is a repository of sites implemented in rails.

Ken
+1  A: 

Which books have you read? I think a better understanding of MVC and Rails would help you more in the long run than sample code, which you may be tempted to copy without understanding.

The problem you're describing isn't really different from finding and displaying any kind of data, which I'm sure you've seen covered in snippets on blogs, etc. (using partials and/or layouts is maybe the only difference).

If you haven't read them already, you should try Agile Web Development with Rails and The Rails Way.

There are also several books that take you through building a sample application that include commentary to make sure you understand what you're doing.

palmsey
I've read The Rails Way, "Simply Rails 2"...I'm editing my question to include some more details.
Steve Klabnik
Agine Web Development with Rails is a good book.
Ken
+1  A: 

Your controller can access any of your models, so if PageController needs to access your NavModel that's fine. I think typically the Nav controller or helper would contain the methods necessary to prepare the navigation view, but without knowing the details of your project I can't say for sure - if you think it's part of the Page logic, then put it there.

You may also be interested in this "What goes where" question.

palmsey
+2  A: 

This might help: Dynamic navigation menu using Menuitem model

pookleblinky
A: 

Heres a howto on highlighting the current menu item in the page you are on

http://snippets.dzone.com/posts/show/2016