路由错误 没有路由匹配 [GET] "/microposts/304 - 删除微帖子 - Michael Hartl 的railstutorial.org 第 11 章

2023-12-12

我正在阅读 Michael Hartl 的 Ruby on Rails 教程http://ruby.railstutorial.org。我在阅读第 11 章时遇到了问题,特别是在尝试删除微博时。

我和该用户遇到同样的问题路由错误 没有路由匹配 [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 服务器时,Windows 上没有 Javascript 运行时当我运行时不断出现rails server命令但是一旦我注释掉了'sass-rails', 'coffee-rails', and 'uglifier'gems 它会成功运行。我使用的是 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 output:

(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问题。


我认为你缺少这两个之一。

//= require jquery
//= require jquery_ujs

我不小心删除了 //= require jquery_ujs 这给了我同样的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

路由错误 没有路由匹配 [GET] "/microposts/304 - 删除微帖子 - Michael Hartl 的railstutorial.org 第 11 章 的相关文章

  • 使用jquery将Json字符串解析为html div

    我有这样的 json 字符串 common search strBusinessName Sun Shine Vision strAddress Amulia St Madhava Pharmacy Jn intPhone cache ta
  • AJAX列表更新,获取新元素并计数

    我有这个 HTML 列表 ul li class username John li li class username Mark li ul 以及通过 AJAX 添加新名称的表单 多个添加以逗号分隔 响应是一个包含名称的列表 name Da
  • 填充重叠的圆形区域

    我有两个相交的圆 我想让相交区域具有颜色 即使这两个圆是透明的 我想我可以找到一些方法用 css 来做到这一点mix blend mode财产 但我没有成功 当然 我可以使圆圈具有颜色并降低其不透明度 但我希望它们是白色或透明的 其中只有重
  • 单选按钮更改事件在 Chrome 或 Safari 中不起作用

    我在页面上有一些单选按钮 当选择 是 时 一些其他控件 下拉列表和文本框 变得可见 如果选择 否 它们将再次变得不可见 这在 FF 和 IE 中运行良好 当我在 Chrome 中使用鼠标时 它确实有效 但是当我在页面上切换时 控件永远不可见
  • window.location.href 不工作

    我的网站是http www collegeanswerz com http www collegeanswerz com 我正在使用导轨 该代码用于搜索大学 我希望用户能够输入大学名称 单击 Enter 然后转到网址 而不是看到搜索结果 如
  • 尝试制作Linux终端但失败

    这可能是一个愚蠢的问题 可能很容易找到 但我对这一切都很陌生 我似乎找不到我要找的东西 或者至少我不知道我需要寻找什么 所以我在这里 所以我想做的是创建一种 Linux 终端 这就是我到目前为止所得到的 我所坚持的是实际输入文本部分 我一直
  • 在 jQuery 中添加 ID?

    是否有任何方法可以像添加类一样添加 ID addClass ID是一个属性 您可以使用attr http docs jquery com Attributes attr keyvalue功能 element attr id newID 我不
  • 安全导航相当于 Rails 尝试哈希值

    在 Rails 中 你可以这样做hash try key 这有帮助如果hash是潜在的nil 是否有使用新的 Ruby 2 3 安全导航运算符的等效版本 with 不等同于 Rails 的try 但你可以使用 对于哈希值 就用用吧 没什么特
  • Rails 从视图中调用操作

    希望这里有一个简单的问题 但我似乎无法找到答案 刚刚开始使用 RoR 但之前来自 ASP MVC 我在渲染部分视图时遇到问题 其局部变量不一定与主视图的变量相关联 例如 对于一个博客 我试图渲染一个链接到存档的侧边栏 def sidebar
  • jQuery:当使用 on .scroll 事件和警报时,firefox 似乎无限循环

    我的主模板之一中有以下 jQuery 代码 document scroll function var scroll top document scrollTop alert scroll top if scroll top lt 70 fi
  • Ruby 中 return 的意义是什么?

    有什么区别return只需放置一个变量 如下所示 没有回报 def write code number of errors if number of errors gt 1 mood Ask me later else mood No Pr
  • 在 JQueryUI 小部件的 QUnit 测试中测试可见性

    这对于其他人来说可能是显而易见的 但我没有通过搜索找到它 所以在这里发布问题和一个可能的答案 背景 使用自定义 JQuery UI 小部件小部件工厂 http jqueryui com widget 在小部件中 某些元素根据其他数据 选项隐
  • 如何在 html5 中加载部分 html? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 询问我们的问题推荐或查找工具 库或最喜欢的场外资源与 Stack Overflow 无关 因为它们往往会吸引固执己见的答案和垃圾邮件 反而
  • 样式表何时添加到 document.styleSheets

    我正在尝试使用 javascript 动态添加 css 样式表规则 例如示例 2here https developer mozilla org en DOM CSSStyleSheet insertRule 它在大多数情况下都有效 但似乎
  • 是否有跨浏览器的 jQuery contentEditable 库? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找一个 jQuery 插件 库 它可以使 contentEditable 属性在所有主要浏览器中正常工作 我什至可以不用 IE6
  • Jquery 对话框打开另一个页面

    有一个页面为transaction html 如何在另一个页面的弹出窗口中打开此页面 例如 jquery 对话框中的 show transactions html dialog html open transaction html in t
  • 为什么“jQuery-Rails”经常位于资产组之外

    为什么我经常看到gem jquery rails之外的 assets group group assets do gem sass rails gt 3 1 0 gem coffee rails gt 3 1 0 gem uglifier
  • 删除多个类 (jQuery)

    有没有更好的方法来重写这个 element removeClass class1 removeClass class2 我无法使用removeClass 因为它会删除我不想要的所有课程 element removeClass class1
  • jquery ui 自动完成添加跨度

    我在 div 上使用 jQuery 自动完成 但我得到了 jquery 自动添加的额外范围 span class ui helper hidden accessible search test span 如何防止创建此跨度 我通过添加 CS
  • Ruby Shoes 打包程序,包括应用程序中的 Shoes

    我似乎无法让 Ruby Shoes 打包程序正确创建包含 Shoes 的 exe 我正在使用 Raisins 版本 0 r1134 并从 github 替换 pack rb 打包程序制作的 exe 都是 70 80K 文件 它们显然不包括

随机推荐