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.
我刚学习Ruby on Rails。我读了几本书,我看了很多Railscasts,我看了一些例子。
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.
然而,当我使用Rails开展我的第一个认真项目时,我已经开始了解如何正确实现一些非常基本的网站功能,这些功能是我见过的大多数教程所缺乏的。
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?
我认为学习这类东西的最好方法是看示例代码。 RoR中有没有好的开源网站?我可以查看的任何示例代码?
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?
我想我的问题确实导致使用MVC。基本的想法是非常基本的,我理解这一点。但似乎大多数应用程序都将每个部分彼此完全分开......如果我想将两个模型的数据组合在一起显示在同一页面上怎么办?举一个我提出的例子,如果我有一个NavModel和一个PageModel,我的PageController可以访问这两个模型吗?我想我认为PageController只能访问PageModel,而不是其他任何一个。我见过的所有例子似乎都是这样运作的...这是一个错误的假设吗?
Or am I totally missing the point, and is that 'doing it wrong?'
或者我完全忽略了这一点,那是“做错了吗?”
5 个解决方案
#1
5
Open Source Rails is a repository of sites implemented in rails.
Open Source Rails是rails中实现的站点的存储库。
#2
3
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.
你看过哪本书?我认为从长远来看,对MVC和Rails的更好理解会比示例代码更有帮助,您可能会在不理解的情况下复制它。
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.
如果您还没有阅读过,那么您应该尝试使用Rails和The Rails Way进行敏捷Web开发。
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.
还有几本书可以帮助您构建包含注释的示例应用程序,以确保您了解自己在做什么。
#4
1
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.
您的控制器可以访问您的任何模型,因此如果PageController需要访问您的NavModel,那很好。我认为通常Nav控制器或帮助器将包含准备导航视图所需的方法,但是如果不知道项目的细节我无法确定 - 如果您认为它是Page逻辑的一部分,那么就把它放在那里。
You may also be interested in this "What goes where" question.
您可能也对这个“What what where”问题感兴趣。
#5
0
Heres a howto on highlighting the current menu item in the page you are on
这是一个关于突出显示您所在页面中当前菜单项的方法
#1
5
Open Source Rails is a repository of sites implemented in rails.
Open Source Rails是rails中实现的站点的存储库。
#2
3
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.
你看过哪本书?我认为从长远来看,对MVC和Rails的更好理解会比示例代码更有帮助,您可能会在不理解的情况下复制它。
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.
如果您还没有阅读过,那么您应该尝试使用Rails和The Rails Way进行敏捷Web开发。
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.
还有几本书可以帮助您构建包含注释的示例应用程序,以确保您了解自己在做什么。
#3
#4
1
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.
您的控制器可以访问您的任何模型,因此如果PageController需要访问您的NavModel,那很好。我认为通常Nav控制器或帮助器将包含准备导航视图所需的方法,但是如果不知道项目的细节我无法确定 - 如果您认为它是Page逻辑的一部分,那么就把它放在那里。
You may also be interested in this "What goes where" question.
您可能也对这个“What what where”问题感兴趣。
#5
0
Heres a howto on highlighting the current menu item in the page you are on
这是一个关于突出显示您所在页面中当前菜单项的方法