2012-05-17 33 views
0

我是新來的鐵軌3(和鐵軌一般)...我建立了一個朋友樂隊的網站骨架,現在他想添加文章到他的網站...Rails 3.2.3路由錯誤(試圖添加文章)

到目前爲止,我建立的所有頁面都是:(主頁,節目,媒體,聯繫人)和標題&頁腳部分...因此沒有太花哨的東西。

繼承人我做了什麼添加文章至今:

rails g scaffold article title:string body:text 
rake db:migrate 

,但是當我去到本地主機:3000 /文章中,我得到這個錯誤信息:

ActionController::RoutingError in Articles#new 
no route matches {:action=>"home", :controller=>"articles"} 

它說錯誤是引發在應用程序/視圖/佈局/ _header.html.erb在線路#28:

25: <h1>Title</h1> 
26: <ul id="nav"> 
27: <ul> 
28:   <li><%= link_to image_tag("home.jpg",:class=> 'hoverImages'), :action => 'home' %></li> 
29:   <li><%= link_to image_tag("shows.jpg", :class=> 'hoverImages'), :action => 'shows' %></li> 
30:   <li><%= link_to image_tag("media.jpg", :class=> 'hoverImages'), :action => 'media' %></li> 
31:   <li><%= link_to image_tag("contact.jpg", :class=> 'hoverImages'), :action => 'contact' %></li> 

這裏是我的的routes.rb

CsmlSite::Application.routes.draw do 

resources :articles 

match '/shows', :to => 'pages#shows' 
match '/media', :to => 'pages#media' 
match '/contact', :to => 'pages#contact' 
match '/articles', :to => 'articles#index' 
root :to => "pages#home" 

end 

爲什麼我不能查看本地主機:3000 /文章? 任何有用的提示將是非常有責任的!

編輯:這裏是我的耙路線任務

root  /(.:format)     {:controller=>"pages", :action=> "home"} 
articles GET /articles(.:format)   {:action=>"index", :controller=>"articles"} 
POST /articles(.:format)   {:action=>"create", :controller=>"articles"} 
new_article GET /articles/new(.:format)  {:action=>"new", :controller=>" articles"} 
edit_article GET /articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"} 
article GET /articles/:id(.:format)  {:action=>"show", :controller=>"articles"} 
PUT /articles/:id(.:format)  {:action=>"update", :controller=>"articles"} 
DELETE /articles/:id(.:format)  {:action=>"destroy", :controller=>"articles"} 
shows  /shows(.:format)    {:controller=>"pages", :action=>"shows"} 
media  /media(.:format)    {:controller=>"pages", :action=>"media"} 
contact  /contact(.:format)   {:controller=>"pages", :action=>"contact"} 
contacts POST /contacts(.:format)   {:action=>"create", :controller=>"contact_us/contacts"} 
new_contact GET /contacts/new(.:format)  {:action=>"new", :controller=>"contact_us/contacts"} 
contact_us  /contact_us(.:format)  {:action=>"new", :controller=>"contact_us/contacts"}` 
+0

從* routes.rb *中刪除'resources:articles'會發生什麼? - 我也建議給你的路線命名,並在'link_to'中使用route_name_path,而不是動作的名字。 –

+0

我試圖從_routes.rb_中刪除'resources:articles' ...現在我收到這個錯誤...'沒有路由匹配{:action =>「new」,:controller =>「articles」}'on _views /articles/index.html.erb_。有什麼建議麼? –

回答

0

Nvm ...算出來了。我的路線與我已安裝的寶石發生衝突......具體爲gem 'contact_us', '~> 0.2.0'

一旦我刪除了那個寶石,我就可以使用shows_pages_path et。全部

0

使用路徑,而不是重寫你的觀點的輸出:動作:

<h1>Title</h1> 
<ul id="nav"> 
    <li><%= link_to image_tag("home.jpg",:class=> 'hoverImages'), root_path %></li> 
    <li><%= link_to image_tag("shows.jpg", :class=> 'hoverImages'), shows_path %></li> 
    <li><%= link_to image_tag("media.jpg", :class=> 'hoverImages'), media_path %></li> 
    <li><%= link_to image_tag("contact.jpg", :class=> 'hoverImages'), contact_path %></li> 
</ul> 

而在你的路線一件事:

CsmlSite::Application.routes.draw do 

    root :to => "pages#home" 

    resources :articles 

    match '/shows', :to => 'pages#shows' 
    match '/media', :to => 'pages#media' 
    match '/contact', :to => 'pages#contact' 

    # the route below is not necessary (it is generated by `resources :articles`) 
    # match '/articles', :to => 'articles#index' 

結束

+0

我繼續前進,試着這....但現在我得到這個錯誤:未定義的局部變量或方法shows_pages_path爲#<#:0x0000010299a680>'當我嘗試訪問本地主機:3000 /文章 –

+0

@ tim-gruns hm ..你能在你的問題的最後粘貼'rake routes'任務的輸出嗎? – melekes

+0

是的......據我所知,一切看起來都很正常。 –