2011-11-23 45 views
2

我正在通過Michael Hartl的Ruby on Rails教程http://ruby.railstutorial.org。 ,特別是在試圖刪除一個微博時路由錯誤沒有路由匹配[GET]「/ microposts/304 - 刪除一個Micropost - Michael Hartl的railstutorial.org第11章

我和這個用戶有同樣的問題Routing Error No route matches [GET] "/microposts/304"他能通過評論jQuery gem來解決問題,但它工作起來。 。幸運

這裏是我當前的Gemfile:

source 'http://rubygems.org' 

gem 'rails', '3.1.1' 

# Bundle edge Rails instead: 
# gem 'rails',  :git => 'git://github.com/rails/rails.git' 

gem 'sqlite3' 
gem 'gravatar_image_tag', '1.0.0.pre2' 
gem 'will_paginate', '3.0.pre2' 

gem 'jquery-rails' 
gem 'pg' 

group :development do 
    gem 'faker', '0.3.1' 
end 


# Gems used only for assets and not required 
# in production environments by default. 
#group :assets do 
# gem 'sass-rails', '~> 3.1.4' 
# gem 'coffee-rails', '~> 3.1.1' 
# gem 'uglifier', '>= 1.0.3' 
#end 

# To use ActiveModel has_secure_password 
# gem 'bcrypt-ruby', '~> 3.0.0' 

# Use unicorn as the web server 
# gem 'unicorn' 

# Deploy with Capistrano 
# gem 'capistrano' 

# To use debugger 
# gem 'ruby-debug19', :require => 'ruby-debug' 

group :test do 
    # Pretty printed test output 
    gem 'turn', :require => false 
end 

=>快速旁註:當我運行rails server命令時,出現錯誤No Javascript runtime on windows when running rails server,但一旦我註釋掉'sass-rails''coffee-rails''uglifier'寶石,它會成功運行。我正在使用Windows PC,並被告知這可能是Windows機器的特定問題。

而且,這裏是我的bundle install命令的當前成果:

Using rake (0.9.2.2) 
Using multi_json (1.0.3) 
Using activesupport (3.1.1) 
Using builder (3.0.0) 
Using i18n (0.6.0) 
Using activemodel (3.1.1) 
Using erubis (2.7.0) 
Using rack (1.3.5) 
Using rack-cache (1.1) 
Using rack-mount (0.8.3) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.0.3) 
Using actionpack (3.1.1) 
Using mime-types (1.17.2) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.3.0) 
Using actionmailer (3.1.1) 
Using arel (2.2.1) 
Using tzinfo (0.3.31) 
Using activerecord (3.1.1) 
Using activeresource (3.1.1) 
Using ansi (1.4.1) 
Using bundler (1.0.21) 
Using faker (0.3.1) 
Using gravatar_image_tag (1.0.0.pre2) 
Using rack-ssl (1.3.2) 
Using json (1.6.1) 
Using rdoc (3.11) 
Using thor (0.14.6) 
Using railties (3.1.1) 
Using jquery-rails (1.0.17) 
Using pg (0.11.0) 
Using rails (3.1.1) 
Using sqlite3 (1.3.4) 
Using turn (0.8.3) 
Using will_paginate (3.0.pre2) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem 
is installed. 

我不知道如何解決這個問題。 爲了讓刪除方法起作用,我需要安裝一個特定的gem嗎?我感謝您的幫助!

這裏是rake routes輸出:

(in C:/rails_projects/sample_app) 
     users GET /users(.:format)   {:action=>"index", :controller=>"us 
ers"} 
      POST /users(.:format)   {:action=>"create", :controller=>"u 
sers"} 
    new_user GET /users/new(.:format)  {:action=>"new", :controller=>"user 
s"} 
    edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"use 
rs"} 
     user GET /users/:id(.:format)  {:action=>"show", :controller=>"use 
rs"} 
      PUT /users/:id(.:format)  {:action=>"update", :controller=>"u 
sers"} 
      DELETE /users/:id(.:format)  {:action=>"destroy", :controller=>" 
users"} 
    sessions POST /sessions(.:format)  {:action=>"create", :controller=>"s 
essions"} 
new_session GET /sessions/new(.:format) {:action=>"new", :controller=>"sess 
ions"} 
    session DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>" 
sessions"} 
microposts POST /microposts(.:format)  {:action=>"create", :controller=>"m 
icroposts"} 
    micropost DELETE /microposts/:id(.:format) {:action=>"destroy", :controller=>" 
microposts"} 
    signup  /signup(.:format)   {:controller=>"users", :action=>"ne 
w"} 
    signin  /signin(.:format)   {:controller=>"sessions", :action=> 
"new"} 
    signout  /signout(.:format)  {:controller=>"sessions", :action=> 
"destroy"} 
    contact  /contact(.:format)  {:controller=>"pages", :action=>"co 
ntact"} 
     about  /about(.:format)   {:controller=>"pages", :action=>"ab 
out"} 
     help  /help(.:format)   {:controller=>"pages", :action=>"he 
lp"} 
     root  /      {:controller=>"pages", :action=>"ho 
me"} 

這裏是使用刪除方法的部分視圖的文件:

<tr> 
    <td class="micropost"> 
    <span class="content"><%= micropost.content %></span> 
    <span class="timestamp"> 
     Posted <%= time_ago_in_words(micropost.created_at) %> ago. 
    </span> 
    </td> 
    <% user = micropost.user rescue User.find(micropost.user_id) %> 
    <% if current_user?(user) %> 
    <td> 
    <%= link_to "delete", micropost, :method => :delete, 
            :confirm => "You sure?", 
            :title => micropost.content %> 
    </td> 
    <% end %> 
</tr> 

同樣,源代碼可以在Github https://github.com/railstutorial/sample_app被查看,它只是似乎不能在我的機器上正常運行,這導致我相信這是user's問題。

+0

您對'rake routes'的輸出是什麼? – sarnold

+0

此外,您用來輸出鏈接/按鈕/刪除帖子的任何視圖代碼是什麼? –

+0

@sarnold:我正在使用rake 0.9.2並且運行'rake routes'不起作用。所以,我遵循這個例子,並切換到耙0.8.7和'耙路線'工作。我將它附加到問題上。 – Abundnce10

回答

2

我想你錯過了其中的一個。

//= require jquery 
//= require jquery_ujs 

我不小心刪除了// =需要jquery_ujs,這給了我同樣的問題。

+1

我犯了同樣的錯誤,在這裏看到你的指針,瞧!問題解決了! –

+1

@NickLewis很好,我可以幫忙。你能把我的答案投給我嗎? – Benjamin

0

您是否在應用程序中同時使用了prototype和jquery?
我可以看到你正在使用jquery-rails gem,但是原型也存在嗎?
檢查是否正在加載,因爲它們相互衝突。

+0

我試着將microposts_controller方法切換到'delete',沒有工作。然後我試着將視圖切換到':destroy',但沒有奏效。嗯... – Abundnce10

+0

我已經更新了答案,看看它是否有幫助。 –

+0

我安裝了'gem'prototype-rails''3.1。0',但刪除功能不起作用 - 它給了我相同的錯誤信息。然後我評論了jQuery gem並嘗試再次運行它,但仍然沒有成功。你是否認爲這與我在嘗試在開發早期執行'rails server'命令時收到的錯誤消息有關,[「Could not find a Javascript runtime。」](http://stackoverflow.com/questions/ 8047651 /無JavaScript的運行時的窗口,當運行護欄服務器)? – Abundnce10

相關問題