Hartl的ruby-on-rails教程第11章中的“删除微博”中的“没有路线匹配”错误-完全被卡住 [英] 'No route matches' Error on Delete of Micropost in Chapter 11 of Hartl's ruby-on-rails tutorial - completely stumped

查看:128
本文介绍了Hartl的ruby-on-rails教程第11章中的“删除微博”中的“没有路线匹配”错误-完全被卡住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找Michael Hartl的ROR教程中一个特别难以捉摸的错误。

I am trying to track down a particularly elusive bug in working through Michael Hartl's ROR Tutorial.

在微博上(从主页或用户/显示页面)单击删除时,URL为 http:// localhost:3000 / microposts / 303 ,但结果是路由错误-没有路由匹配 / microposts / 303。

When clicking on 'Delete' for a micropost (from the home page or the user/show page) the url is http://localhost:3000/microposts/303, but the result is "Routing Error - No route matches"/microposts/303".

我浏览了涉及的代码的每一页,并用Hartl的gitHub项目站点中的代码替换了它们。 https://github.com/railstutorial/sample_app 。例如,对于microposts_controller,我从gitHub软件仓库复制了代码,并用复制的代码替换了代码,然后重新启动

I have gone through each page of my code that is involved and replaced them with code from Hartl's gitHub project site. https://github.com/railstutorial/sample_app. For example, for the microposts_controller, I copied the code from the gitHub depot and replaced my code with the copied code. I then restarted the server. Same result. I then reverted back to my code to test the next page.

交换代码的页面是

控制器
microposts_controller
users_controller(显示方法)

CONTROLLERS microposts_controller users_controller (show method)

模型
micropost.rb(模型)

MODEL micropost.rb (model)

观看次数
microposts / _micropost.haml
共享/_micropost_form.html.haml
共享/_feed.haml
共享/_feed_item.haml

VIEWS microposts/_micropost.haml shared/_micropost_form.html.haml shared/_feed.haml shared/_feed_item.haml

和路线文件。

我不知所措要检查其他东西。有人有什么建议吗?

I am at a loss for other things to check. Does anyone have any suggestions?

谢谢

Dave

耙路的结果

 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文件是

The Routes.rb file is

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上的路由文件替换了我的路由文件也无法解决问题。

But, as I said, even replacing my routes file with the one on gitHub did not resolve the issue.

要删除的链接是

 = link_to "delete", micropost, :method => :delete,
                                      :confirm => "You sure?",
                                      :title => micropost.content


推荐答案

link_to:方法=> :delete 使用简洁的JavaScript来创建 DELETE 请求。我的猜测是,您的项目中没有必要的javascript文件(prototype.js / jquery.js和rails.js),或者您没有在布局中包括它们。

link_to :method => :delete uses unobtrusive javascript to create the DELETE request. My guess is that you either don't have the necessary javascript files in your project (prototype.js/jquery.js and rails.js) or you are not including them in your layout.

这篇关于Hartl的ruby-on-rails教程第11章中的“删除微博”中的“没有路线匹配”错误-完全被卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆