简体   繁体   English

Ruby / Rails如何创建从一个视图到另一视图的链接

[英]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.

相关问题 Ruby on Rails:如何使用不同的控制器从一个视图/页面链接/路由到另一个视图/页面 - Ruby on Rails: How to link/route from one view/page to another view/page with a different controller Link_to另一个视图在轨道上的红宝石 - Link_to another view ruby on rails 如何将一个控制器的局部视图渲染到轨道上的ruby中的另一个控制器 - How to render partial view of one controller to another controller in ruby on rails 如何在Ruby on Rails中将HTML站点链接到任何站点 - How to link from html site to any site in view in Ruby on Rails 如何使用POST在Ruby on Rails中将参数从一个视图传递到另一个视图 - How to pass a param from one view to another in Ruby on Rails, using POST 在Ruby on Rails中创建视图 - Create View in Ruby on Rails Rails:将创建模型从一个模型显示到另一个模型视图中 - Rails: display create form from one model into another model view 如何在 Ruby on Rails 中创建嵌套到另一个视图文件的视图控制器? - How to create a view's controller that nested to another view file in Ruby on Rails? 如何使用一个控制器视图作为Ruby on Rails中另一个控制器的局部视图 - How to use one controller view as a partial view for another controller in Ruby on Rails 如何在Ruby on Rails中将参数传递给另一个视图 - How to pass a parameter to another View in Ruby on Rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM