简体   繁体   中英

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. 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

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. But to answer your question...

In your routes.rb :

Rails.application.routes.draw do
  get 'reports#index'
  get 'health#index'
end

Then, in your health/index.html.erb file:

<%= link_to 'Reports Index', reports_path %>

This will create a link that, when clicked on, will go to the Reports Index page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM