我是rails 3的新手(以及一般的导轨)......我为朋友乐队建立了一个网站骨架,现在他想在他的网站上添加文章......
到目前为止,我所建立的只有页面:(家庭,演出,媒体,联系人)和标题&页脚部分...所以没什么太花哨的。
到目前为止我做了添加文章的内容:
rails g scaffold article title:string body:text
rake db:migrate
但是当我去localhost:3000 /文章时,我收到此错误消息:
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>
这是我的 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
为什么我不能查看localhost: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 :(得分: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'
端
答案 1 :(得分:0)
Nvm ......想通了。我的路线与我安装的宝石发生了冲突......特别是gem 'contact_us', '~> 0.2.0'
。
一旦我删除了这个宝石,我就可以使用shows_pages_path
等。所有