我不能删除在Rails的帖子(I can't delete a post in Rails)

2019-10-20 04:01发布

我试图破坏铁轨后(照片),但它一直引导到该职位的show'page。

意见/照片/ 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("/")

当我点击的照片”指数销毁记录的权利

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

Answer 1:

这使得该链接进行删除相同的代码是创建确认弹出(代码jquery_ujs )。 如果弹出未显示,在UJS代码不能工作。 你有权利要求你陈述application.js

//= require jquery
//= require jquery_ujs


Answer 2:

你重定向到PHOTOS_URL。

  format.html { redirect_to photos_url }

您可以从您的耙路输出这里做了一堆东西,喜欢request.referer,另一条路径,或者手动确定在何处取决于你在破坏行动得到PARAMS去



文章来源: I can't delete a post in Rails