我正试图通过Michael Hartl的ROR教程来追踪一个特别难以捉摸的错误。
点击微博的“删除”(从主页或用户/节目页面),网址为http://localhost:3000/microposts/303,但结果是“路由错误 - 没有路由匹配”/ microposts / 303“ 。
我已经浏览了所涉及的代码的每一页,并用来自Hartl的gitHub项目站点的代码替换它们。 https://github.com/railstutorial/sample_app。例如,对于microposts_controller,我从gitHub库中复制了代码,并用复制的代码替换了我的代码。然后我重新启动了服务器。结果相同。然后我又回到我的代码来测试下一页。
我交换代码的页面是
控制器 microposts_controller users_controller(show method)
MODEL micropost.rb(模型)
视图 微柱/ _micropost.haml 共享/ _micropost_form.html.haml 共享/ _feed.haml 共享/ _feed_item.haml
和Routes文件。
我无法检查其他事情。有没有人有任何建议?
谢谢,
戴夫
佣金路线的结果
sessions POST /sessions(.:format) {:action=>"create", :controller=>"sessions"}
new_session GET /sessions/new(.:format) {:action=>"new", :controller=>"sessions"}
session DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>"sessions"}
signin /signin(.:format) {:controller=>"sessions", :action=>"new"}
signout /signout(.:format) {:controller=>"sessions", :action=>"destroy"}
microposts POST /microposts(.:format) {:action=>"create", :controller=>"microposts"}
micropost DELETE /microposts/:id(.:format) {:action=>"destroy", :controller=>"microposts"}
root /(.:format) {:controller=>"pages", :action=>"home"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
about /about(.:format) {:controller=>"pages", :action=>"about"}
help /help(.:format) {:controller=>"pages", :action=>"help"}
signup /signup(.:format) {:controller=>"users", :action=>"new"}
development /development(.:format) {:controller=>"pages", :action=>"development"}
/signup(.:format) {:controller=>"users", :action=>"new"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
Routes.rb文件是
SampleApp::Application.routes.draw do
#Sign in Routes
resources :sessions, :only => [:new, :create, :destroy]
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
#Microposts Routes
resources :microposts, :only => [:create, :destroy]
#Pages Routes
root :to => "pages#home"
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/signup', :to => 'users#new'
match '/development', :to => 'pages#development'
#Users Routes
match '/signup', :to => 'users#new'
resources :users
end
但是,正如我所说,即使用gitHub上的那个替换我的路由文件也无法解决问题。
要删除的链接是
= link_to "delete", micropost, :method => :delete,
:confirm => "You sure?",
:title => micropost.content
答案 0 :(得分:3)
link_to :method => :delete
使用不显眼的javascript来创建DELETE
请求。我的猜测是你在项目中没有必要的javascript文件(prototype.js / jquery.js和rails.js),或者你没有将它们包含在你的布局中。