[英]How to create a link from the welcome page to another ruby page
at the moment, my nav-bar content looks like this: 目前,我的导航栏内容如下所示:
<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>
The first two links work fine, but the last one doesn't. 前两个链接可以正常工作,但最后一个则不能。 How do I refer correcty?
我该如何指正? The contact page is just a simple, static page (no projects, or blogs that get pushed).
联系人页面只是一个简单的静态页面(没有项目或需要推送的博客)。
This my routes.rb 这是我的routes.rb
Rails.application.routes.draw do
resources :contact
get 'contact/index'
resources :posts
resources :projects
get 'welcome/index'
root 'welcome#index'
end
And this is the controller 这是控制器
class ContactController < ApplicationController
def index
end
end
If I take a look at the rake routes, I am get this: 如果我看一下耙道,我会得到:
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
I am new at ruby and I am looking forward to help. 我是ruby的新手,我期待提供帮助。 Thanks already in advance!
在此先感谢!
将您的第三行替换为以下行:
<li><%= link_to 'Contact', contact_index_path, class: "header" %></li>
Get rid of get 'contact/index'
from your routes file and try. 摆脱从您的路线文件中
get 'contact/index'
并尝试的方法。
You already have a path for index of contact
, when you added resources :contact
添加
resources :contact
时,您已经有了一个contact
索引的路径resources :contact
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.