[英]Ruby/Rails How to create link from one view to another view
I am new to ruby/rails and have been learning by creating a simple application. 我是ruby / rails的新手,并且已经通过创建一个简单的应用程序来学习。 I have a simple view where I want to add a button which when clicked will take you to another view.
我有一个简单的视图,我想在其中添加一个按钮,单击该按钮会将您带到另一个视图。 I tried adding controller and configure the routes but still not sure how to proceed.
我尝试添加控制器并配置路由,但仍不确定如何继续。
The project structure looks like 项目结构看起来像
app
controller
health
report
view
health
index
reports
index
I created a new controller called reports and in my routes.rb I added 我创建了一个名为reports的新控制器,并在我的route.rb中添加了
Rails.application.routes.draw do
get 'reports/index'
end
There are two things I want to do. 我想做两件事。 Add a button in health/index file which when click will view reports/index.
在运行状况/索引文件中添加一个按钮,单击该按钮将查看报告/索引。 How to do this ?
这个怎么做 ?
I agree with max about reading up on MVC and doing the Rails Tutorial. 我同意max关于阅读MVC和编写Rails教程的知识。 But to answer your question...
但是要回答你的问题...
In your routes.rb
: 在您的
routes.rb
:
Rails.application.routes.draw do
get 'reports#index'
get 'health#index'
end
Then, in your health/index.html.erb
file: 然后,在您的
health/index.html.erb
文件中:
<%= link_to 'Reports Index', reports_path %>
This will create a link that, when clicked on, will go to the Reports Index page. 这将创建一个链接,单击该链接将转到“报告索引”页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.