![](/img/trans.png)
[英]Ruby on Rails: How to link/route from one view/page to another view/page with a different controller
[英]Ruby/Rails How to create link from one view to another view
我是ruby / rails的新手,并且已经通过创建一个简单的应用程序来学习。 我有一个简单的视图,我想在其中添加一个按钮,单击该按钮会将您带到另一个视图。 我尝试添加控制器并配置路由,但仍不确定如何继续。
项目结构看起来像
app
controller
health
report
view
health
index
reports
index
我创建了一个名为reports的新控制器,并在我的route.rb中添加了
Rails.application.routes.draw do
get 'reports/index'
end
我想做两件事。 在运行状况/索引文件中添加一个按钮,单击该按钮将查看报告/索引。 这个怎么做 ?
我同意max关于阅读MVC和编写Rails教程的知识。 但是要回答你的问题...
在您的routes.rb
:
Rails.application.routes.draw do
get 'reports#index'
get 'health#index'
end
然后,在您的health/index.html.erb
文件中:
<%= link_to 'Reports Index', reports_path %>
这将创建一个链接,单击该链接将转到“报告索引”页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.