【发布时间】:2012-01-04 09:17:20
【问题描述】:
我正在阅读 Michael Hartl 在 http://ruby.railstutorial.org 上的 Ruby on Rails 教程。我在第 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' 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 的输出:
(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 问题类似。
【问题讨论】:
-
rake routes的输出是什么? -
另外,您用于输出链接/按钮/删除帖子的任何内容的视图代码是什么?
-
@sarnold:我使用 rake 0.9.2 并运行
rake routes没有用。所以,我按照这个 stackoverflow.com/questions/6085610/…> 示例并切换到 rake 0.8.7 和rake routes工作。我将其附加到问题中。 -
@BrandonTilley:我添加了调用删除函数的视图部分。如果您需要其他文件,请告诉我。谢谢你的时间!
标签: jquery ruby-on-rails ruby ruby-on-rails-3 rubygems