![](/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.