2011-11-25 128 views
0

我正在使用Michael Hartl的rails教程,就像rails中的其他新手一樣。無論如何,我被困在第11章一樣的一些JQuery不與刪除行動問題。也就是說,當點擊任何刪除按鈕,它只會將我重定向到一個特定的錯誤頁面,說「沒有路由匹配[GET]」/ microposts/301「jQuery不能在Michael Hartl的教程第11章的刪除操作上工作

我在_micropost.html.erb頁面中的代碼是下面:

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

所以,我和我的寶石檢查文件是否有原型和jQuery的衝突或不 我發現了什麼是如下

source 'http://rubygems.org' 

gem 'rails', '3.1.1' 
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git' 

# 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' 
# 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 

gem 'jquery-rails' 


group :development do 
    gem 'rspec-rails', '2.6.1' 
    gem 'faker', '0.3.1' 
end 

group :test do 
    gem 'rspec-rails', '2.6.1' 
    gem 'webrat', '0.7.1' 
    gem 'factory_girl_rails', '1.0' 
end 

group :production do 
    gem 'therubyracer-heroku', '~> 0.8.1.pre3', :platform => :ruby 
    #gem 'therubyracer-heroku', '0.8.1.pre3' # you will need this too 
    gem 'pg' 
end 

所以,我十分確定這裏有沒有安裝原型,正如我聽說jQu的導軌3.1一樣ery默認使用。

任何意見,你認爲它爲我工作?在哪裏檢查我的jQuery已經正確安裝。

根據@塔克的建議,我張貼我的routes.rb在這裏。

SampleApp::Application.routes.draw do 
    resources :users 
    resources :sessions, :only => [:new, :create, :destroy] 
    resources :microposts, :only => [:create, :destroy] 

    match '/signup', :to => 'users#new' 
    match '/signin', :to => 'sessions#new' 
    match '/signout', :to => 'sessions#destroy' 

    match '/contact', :to => 'pages#contact' 
    match '/about', :to => 'pages#about' 
    match '/help', :to => 'pages#help' 

    root :to => 'pages#home' 

    get "pages/home" 

    get "pages/contact" 

    get "pages/about" 

end 
+0

你可以通過檢查「腳本」部分中的Firebug/Chrome來檢查jQuery是否正在加載。但它更可能是路由或控制器的問題。 –

+0

http://stackoverflow.com/a/8524693/1092806 – mockturtl

回答

1

雖然我從來沒有用過的回報率,就好像您在面臨任何開發利用的MVC框架的經典問題 - 那就是,在夜的link_to處理點的動作無效路線。根據你的代碼,顯然micropost是你的模型,但我們不知道模型的發送位置是什麼......你可以看一下腳本的html輸出(使用瀏覽器的內置開發工具或者只是查看源代碼)並驗證生成的url是否有效和/或b)發佈爲您的應用程序配置的路線映射?發佈要麼/或將使它更容易爲社會,以幫助您解決問題...

+0

我現在工作了!我查看了源代碼頁面中的代碼,逐個檢查了每個引用,然後發現jquery相關文件不在其預期的位置。所以,我剛剛從另一個可用的應用程序文件夾複製了jquery.js和jquery_ujs.js。現在,它的功能就像一個魅力。 –

0

檢查,如果你看行 <%= stylesheet_link_tag%>在您的佈局文件application.html.erb

如果你沒有它,那麼你的刪除腳本將不起作用

相關問題