jQuery在Michael Hartl教程的第11章中无法执行删除操作 [英] jQuery not working at delete action on Michael Hartl's tutorial, chapter 11

查看:67
本文介绍了jQuery在Michael Hartl教程的第11章中无法执行删除操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像其他新手一样,在Michael Hartl编写的Rails教程中工作. 无论如何,我也像第十一章一样被困在第11章,因为有些JQuery无法处理删除动作问题.也就是说,单击任何删除按钮时,它只会将我重定向到一个特定的错误页面,该页面显示没有匹配[GET]的路由//microposts/301"

I'm working on rails tutorial by Michael Hartl like other newbies in rails do. anyway, I'm stuck at the chapter 11 like those too with some JQuery not working with delete action issue. That's to say, when clicking on any delete button, it only redirects me to a particular error page saying "No route matches [GET] "/microposts/301"

我在_micropost.html.erb页面中的代码如下:

My code in the _micropost.html.erb page is as below:

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

因此,我检查了我的gem文件是否具有原型和jQuery冲突. 我发现的情况如下

So, I checked with my gem file whether it had prototype and jQuery conflict or not. what I found is as below

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

因此,我非常确定这里没有安装原型,因为我听说在Rails 3.1以后的版本中默认使用jQuery.

So, I am quite so sure here there is no prototype installed, as I heard for the rails 3.1 onward the jQuery is used by default.

您有任何建议让它对我有用吗?在哪里检查我的jQuery是否已正确安装.

Any advice that you think to get it working for me? Where to check that my jQuery is already installed properly.

根据@Tuck的建议,我在此处发布我的route.rb.

As per @Tuck's suggestion, I post my routes.rb here.

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

推荐答案

虽然我从未使用过RoR,但似乎任何开发人员都在利用MVC框架时遇到了一个经典问题-也就是说, yoru link_to处理程序指向无效的路由.根据您的代码,很明显,micropost是您的模型,但是我们不知道该模型将发送到哪里...您能否a)查看脚本的html输出(使用浏览器的内置开发人员工具,或者只需查看源代码)并验证生成的网址是否有效和/或b)发布为您的应用配置的路由映射?发贴/或发贴将使社区更轻松地帮助您解决问题...

While I've never used RoR, it seems like you're having a classic issue faced by any developer leveraging an MVC framework - that is, the action in yoru link_to handler points to an invalid route. Based on your code it's apparent that micropost is your model, but we have no idea where that model is being sent... Can you a) take a look at the html output from the script (use your browser's built-in developer tools or just view source) and verify that the generated url is valid and/or b) post the route mappings that are configured for your app? Posting either/or would make it much easier for the community to help you troubleshoot the problem...

这篇关于jQuery在Michael Hartl教程的第11章中无法执行删除操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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