Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

routing - 'No route matches' Error on Delete of Micropost in Chapter 11 of Hartl's ruby-on-rails tutorial - completely stumped

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

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".

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.

The pages I swapped the code with are

CONTROLLERS microposts_controller users_controller (show method)

MODEL micropost.rb (model)

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

and the Routes file.

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

Thanks,

Dave

The results of rake 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"}

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

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

The link to delete is

 = link_to "delete", micropost, :method => :delete,
                                      :confirm => "You sure?",
                                      :title => micropost.content
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...