簡體   English   中英

Ruby / Rails如何創建從一個視圖到另一視圖的鏈接

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM