简体   繁体   English

Ruby on Rails,路由

[英]Ruby on Rails, Routing

Just wanted to know, what does this line mean in the routes.rb file: 只是想知道,这行在routes.rb文件中意味着什么:

AppName::Application.routes.draw do

Please explain. 请解释。 I am new to Rails. 我是Rails的新手。

Have a read through this page . 阅读本页 Basically, within the block passed to Application.routes.draw (which is just a call to a method defined in ActionDispatch::Routing module within the Rails core framework), you define all the URLs/Paths that you want your Rails application to respond to. 基本上,在传递给Application.routes.draw的块中(这只是对Rails核心框架内ActionDispatch :: Routing模块中定义的方法的调用),您可以定义希望Rails应用程序响应的所有URL /路径至。

You can see all these route definitions, by running: 您可以通过运行以下命令查看所有这些路由定义:

rake routes

in your terminal. 在你的终端。

It is the main routes file which defines the root and other paths for the link. 它是主路由文件,用于定义链路的根路径和其他路径。 It is used as suppose you want to change your index page from default ruby on rails to your index page you make changes to file and add 它被用来假设你想要将你的索引页面从rails上的默认ruby更改为你对文件进行更改并添加的索引页面

 root to: "controllername#index"

This file is also used to add the model to the application 此文件还用于将模型添加到应用程序

 resources: "model_name"

Apart from this you can also define links in your rails application 除此之外,您还可以在rails应用程序中定义链接

get 'courses/index'

So going from courses controller to view of the index. 所以从课程控制器到索引的视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM