我无法在 Rails 中删除帖子 [英] I can't delete a post in Rails
本文介绍了我无法在 Rails 中删除帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试销毁 rails 中的帖子(照片),但它一直指向帖子的显示页面.
I'm trying to destroy a post (Photo) in rails but it keeps directing to the show'page of the post.
views/photos/index.html.erb
views/photos/index.html.erb
<td><%= link_to 'Destroy', photo, method: :delete, data: { confirm: 'Are you sure?' } %></td>
路线
resources :photos
resources :billets
devise_for :users
get 'information/index'
get 'information/afficher'
root to: 'information#index'
get "*path" => redirect("/")
当我点击照片索引中的销毁时立即记录
logs right when I click on Destroy in the Photo' index
Started GET "/photos/1" for 127.0.0.1 at 2014-05-23 19:13:22 -0400
Processing by PhotosController#show as HTML
Parameters: {"id"=>"1"}
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Photo Load (0.1ms) SELECT `photos`.* FROM `photos` WHERE `photos`.`id` = 1 LIMIT 1
------------ With this action I will SHOW the given Photo------
Rendered photos/show.html.erb within layouts/application (0.8ms)
Completed 200 OK in 13ms (Views: 9.9ms | ActiveRecord: 0.2ms)
我的破坏行动
def destroy
puts "With this action I will destroy the given Photo"
@photo.destroy
respond_to do |format|
format.html { redirect_to photos_url }
format.json { head :no_content }
end
end
推荐答案
使链接执行 DELETE 的相同代码是创建确认弹出窗口的代码 (jquery_ujs).如果弹出窗口未显示,则 UJS 代码一定不起作用.您的 application.js
中是否有正确的 require 语句?
The same code that makes the link perform a DELETE is the code that creates the confirmation popup (jquery_ujs). If the popup isn’t showing, the UJS code must not be working. Do you have the right require statements in your application.js
?
//= require jquery
//= require jquery_ujs
这篇关于我无法在 Rails 中删除帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文