0

我是 rails 3 的新手(以及一般的 rails)...我为一个朋友乐队建立了一个网站骨架,现在他想在他的网站上添加文章...

到目前为止,我所构建的只是页面:(主页、节目、媒体、联系人)和页眉和页脚部分......所以还没有什么太花哨的东西。

到目前为止,这是我为添加文章所做的工作:

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

但是当我访问 localhost:3000/articles 时,我收到以下错误消息:

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

它说错误是在第 28 行的 app/views/layouts/ _header.html.erb中引发的:

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>

这是我的路线.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

为什么我不能查看 localhost:3000/articles ?任何有用的提示都会非常感激!

编辑:这是我的rake route任务的输出

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"}`
4

2 回答 2

0

使用路径而不是 :action 重写您的视图:

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

结尾

于 2012-05-17T20:18:15.080 回答
0

Nvm...想通了。我的路线与我安装的宝石发生冲突......特别是gem 'contact_us', '~> 0.2.0'

一旦我移除了那个宝石,我就可以使用shows_pages_pathet。全部

于 2012-05-19T21:49:56.053 回答