有关 Ruby on Rails 架构的问题
我目前刚刚开始从事一个项目。这是我的本地服务器,以便您可以看到我所指的内容:
128.48.204.195:3000
当您将鼠标悬停在“格式”的顶部导航上时,我想链接到格式页面。
我面临的问题是是否手动创建链接,或者使用脚手架或其他 MVC 架构技术来创建似乎是由控制器和模型组成的整个基础架构。
在 Ruby on Rails 中添加新页面(显然带有模型和控制器)有哪些优雅且实用的方法?
I am currently just beginning to work on a project. Here is my local server so that you can see what I am referring to:
128.48.204.195:3000
When you mouse over the top navigation for "Formats" I want to link to a page for formats.
The issue I am facing is whether to create a link by hand, or to use scaffolding, or other MVC architecture techniques to create what seems to be a whole infrastructure that gets made with controllers and models.
What are some elegant and good-practice ways to add new pages, which obviously come with models and controllers, in Ruby on Rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您可以在 config/routes.rb 中定义链接,并通过
link_to
方法在视图中使用它们,或者通过redirect_to
在控制器中使用它们>。路由表不仅帮助定义链接生成器方法(如
format_path
),还帮助定义解析器,该解析器接受/formats
的传入请求并将其转换为参数{ :控制器=> '格式', :action => 'index' }
用于由该控制器执行(如果已定义)。当您谈论“页面”时,您可能指的是“我可以在控制器上下文中执行的操作”,在这种情况下,您需要同时添加路由和控制器。您可能指的是具有更多动态内容的页面,这可能意味着内容管理系统,其中有许多可用作 Rails 的插件。
Generally you define the links in
config/routes.rb
and make use of them in your views with thelink_to
method, or in the controllers withredirect_to
.The routing table helps define not only your link generator methods like
format_path
, but the parser that takes the incoming request for/formats
and turns it into the parameters{ :controller => 'formats', :action => 'index' }
for execution by that controller, if defined.When you're talking about "pages" you may mean "actions I can execute in the context of my controllers" in which case you need to add routes and controllers in tandem. You may mean pages with more dynamic content, and that might mean a content management system, of which there are many available as plug-ins for Rails.