![](/img/trans.png)
[英]Ruby on Rails: How to link/route from one view/page to another view/page with a different controller
[英]How to create a link from the welcome page to another ruby page
目前,我的導航欄內容如下所示:
<li><%= link_to "Portfolio", projects_path, :class => "header" %></li>
<li><%= link_to "Articles", posts_path, :class => "header" %></li>
<li><%= link_to 'Contact', contact_path, :class => "header" %></li>
前兩個鏈接可以正常工作,但最后一個則不能。 我該如何指正? 聯系人頁面只是一個簡單的靜態頁面(沒有項目或需要推送的博客)。
這是我的routes.rb
Rails.application.routes.draw do
resources :contact
get 'contact/index'
resources :posts
resources :projects
get 'welcome/index'
root 'welcome#index'
end
這是控制器
class ContactController < ApplicationController
def index
end
end
如果我看一下耙道,我會得到:
contact_index GET /contact(.:format) contact#index
POST /contact(.:format) contact#create
new_contact GET /contact/new(.:format) contact#new
edit_contact GET /contact/:id/edit(.:format) contact#edit
contact GET /contact/:id(.:format) contact#show
PATCH /contact/:id(.:format) contact#update
PUT /contact/:id(.:format) contact#update
DELETE /contact/:id(.:format) contact#destroy
GET /contact/index(.:format) contact#index
我是ruby的新手,我期待提供幫助。 在此先感謝!
將您的第三行替換為以下行:
<li><%= link_to 'Contact', contact_index_path, class: "header" %></li>
擺脫從您的路線文件中get 'contact/index'
並嘗試的方法。
添加resources :contact
時,您已經有了一個contact
索引的路徑resources :contact
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.