路由错误没有路由匹配[GET]“/ microposts / 304 - 删除Micropost - Michael Hartl的railstutorial.org第11章 [英] Routing Error No route matches [GET] "/microposts/304 - Deleting a Micropost - Michael Hartl's railstutorial.org Chapter 11

查看:130
本文介绍了路由错误没有路由匹配[GET]“/ microposts / 304 - 删除Micropost - Michael Hartl的railstutorial.org第11章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Michael Hartl的Ruby on Rails教程学习 http://ruby.railstutorial.org 。我在第11章遇到问题,尤其是在试图删除微博时。

I'm working through Michael Hartl's Ruby on Rails tutorial on http://ruby.railstutorial.org. I'm having trouble with Chapter 11, specifically when attempting to delete a micropost.

我遇到与此用户相同的问题路由错误没有路由匹配[GET]/ microposts / 304。他能够通过评论jQuery gem来解决问题,并且工作起来。然而,我并没有那么幸运。

I'm having the same problem as this user Routing Error No route matches [GET] "/microposts/304". He was able to solve the problem by commenting out the jQuery gem and it worked. I, however, wasn't as lucky.

以下是我目前的Gemfile:

Here is my current 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

=>快速旁注:错误没有Javascript运行时窗口时,运行轨服务器不断出现,当我跑 rails server 命令,但是一旦我注释掉'sass-rails''coffee- rails''uglifier' gems它会成功运行。我正在使用Windows PC,并被告知这可能是Windows机器的特定问题。

=> A quick side-note: An error No Javascript runtime on windows when running rails server kept arising when I ran the rails server command but once I commented out the 'sass-rails', 'coffee-rails', and 'uglifier' gems it would run successfully. I'm using a Windows PC and was told that this might be a specific problem to Windows machines.

另外,这里是我的 bundle install 命令:

Also, here is the current outcome of my bundle install command:

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.

我不知道如何解决这个问题。 为了使删除方法正常工作,是否需要安装特定的宝石?我感谢您的帮助!

I'm not sure how to solve this problem. Is there a specific gem that I need to install in order for the delete method to work? I appreciate your help!

以下是 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"}

以下是使用删除方法的部分视图文件:

Here is a partial view file using the delete method:

<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 ,它似乎没有在我的机器上正常运行,这导致我相信它是沿着行,因为这用户的问题。

Again, the source code can be viewed on Github https://github.com/railstutorial/sample_app, it just seems to not be running properly on my machine which leads me to believe it is something along the lines as this user's problem.

推荐答案

我认为您错过了其中的一个。 b

I think you are missing one of these two.

//= require jquery
//= require jquery_ujs

我意外删除了// =需要jquery_ujs,这给了我同样的问题。

I accidentally removed //= require jquery_ujs and this gave me the same problem.

这篇关于路由错误没有路由匹配[GET]“/ microposts / 304 - 删除Micropost - Michael Hartl的railstutorial.org第11章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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