我是ruby / rails的新手,并且通过创建一个简单的应用程序来学习。我有一个简单的视图,我想添加一个按钮,单击该按钮将带您到另一个视图。我尝试添加控制器并配置路由,但仍不确定如何继续。
项目结构类似于
app
controller
health
report
view
health
index
reports
index
我创建了一个名为reports的新控制器,并在我的routes.rb中添加了
Rails.application.routes.draw do
get 'reports/index'
end
我想做两件事。在运行状况/索引文件中添加一个按钮,单击该按钮将查看报告/索引。怎么做?
答案 0 :(得分:4)
我同意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 %>
这将创建一个链接,当单击该链接时,将转到“报告索引”页面。