2017-02-24 67 views
0

嘿,夥計們一些幫助,這是我的路線文件我需要在軌路由

Rails.application.routes.draw do 
    get 'home/store' 
    get 'home/chat' 
    get 'home/index' 
    root 'home#index' 
    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 
end 

,這是我的控制器

class HomeController < ApplicationController 
    def index 
    end 

    def chat 
    end 

    def store 
    end 
end 

,我連接我的三個頁面index.html.erb, chat.html.erb,store.html.erb這是在主文件夾中 像這樣application.html.erb

<ul class="nav navbar-nav"> 
    <li><link_to "Home","index.html></li> 
    <li><link_to "Buy Games","store.html"%></li> 
    <li><link_to "Watch Videos","#"%></li> 
    <li><link_to "Ask The Experts","chat.html"%></li> 
</ul> 

現在的問題是,我的根是哪裏localhost:3000工作正常,但是當我打開任何其他鏈接像通過application.html.erb聊天,然後地址欄是這樣的「localhost:3000/chat.html.erb」但我的文件的位置是在視圖/ home/chat.html.erb同樣的事情發生時,我打開任何其他鏈接
所以我應該怎麼做,使路由工作還試圖把家\ chat.html在鏈接標籤在apllication.html.erb它的作品,但當我回去它添加另一個\家在地址欄中

也我的背景圖像,我把內聯風格顯示,但是當我打開任何其他網頁,如聊天。 html.erb然後內聯css背景圖像不上傳

+0

請參閱的link_to例如:http://api.rubyonrails.org/classes/ActionView /Helpers/UrlHelper.html#method-i-link_to –

+0

你必須添加資源路徑,像這樣'link_to「home」,root_path' –

回答

0

首先,請務必查看stack overflow's markdown guide以幫助您設置帖子的樣式以使其可讀。另外,歡迎來到堆棧溢出:)

好吧,所以它看起來像你不完全正確的語法來指定你的鏈接使用軌'link_to助手與erb。正確的語法是:

<%= link_to "my link", your_route %> 

但它看起來像你鍵入:

<link_to "Home","index.html> 

你錯過了關閉「,並沒有正常打開或關閉ERB標籤,使正確的語法是:

<%= link_to "Home", "index.html" %> 

然後終於爲所有鏈接:

<li><%= link_to "Home", "index.html" %></li> 
<li><%= link_to "Buy Games", "store.html" %></li> 
<li><%= link_to "Watch Videos","#" %></li> 
<li><%= link_to "Ask The Experts","chat.html" %></li> 

請務必查看關於link_to助手的rails guides以獲取更多信息。

希望有所幫助,祝你好運!

1

您需要

config/routes.rb

Rails.application.routes.draw do 
    get '/home/store', to: "home#store", as: :store 
    get '/home/chat', to: "home#chat", as: :chat 
    get '/home/index', to: "home#index", as: :index 
    root 'home#index' 
    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 
end 

您application.html.erb

<ul class="nav navbar-nav"> 
    <li><%= link_to "Home", root_path %></li> 
    <li><%= link_to "Buy Games",store_path %></li> 
<li><%= link_to "Ask The Experts", chat_path %></li> 
</ul>