简体   繁体   中英

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

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

You already have a path for index of contact , when you added resources :contact

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