我无法删除Rails中的帖子

时间:2014-05-23 23:16:41

标签: ruby-on-rails ruby-on-rails-4

我正试图在铁轨中摧毁一个帖子(照片),但它一直指向帖子的节目页面。

视图/照片/ 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("/")
当我点击照片'索引

中的Destroy时,

正确登录

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

2 个答案:

答案 0 :(得分:1)

使链接执行DELETE的相同代码是创建确认弹出窗口的代码(jquery_ujs)。如果未显示弹出窗口,则UJS代码不能正常工作。您在application.js

中是否有正确的需求声明?
//= require jquery
//= require jquery_ujs

答案 1 :(得分:-2)

您正在重定向到photos_url。

  format.html { redirect_to photos_url }

你可以在这里做一些事情,比如request.referer,rake路径输出的另一条路径,或者根据你在destroy动作中获得的参数手动确定去哪里