2016-11-12 106 views
0

我正在使用devise和我的销毁链接路径不能在我的rails应用程序上工作,我不知道为什么:/当我点击它时,它调用'show'方法。我花了一些时间来研究这个问题。销毁链接路径不工作

我相信问题在我的index.html.erb文件中。看看:)我明白'pin'这个词不应该跟着'destroy'的链接,因为这是调用show方法,但我不知道还有什么要放在那里。

Index.html.erb:

<div id="pins"> 
<% @pins.each do |pin| %> 
     <div class="box"> 
     <%= image_tag pin.image.url %> 
     <%= pin.description %> 
     <%= pin.user.email if pin.user %> 
     <%= link_to 'Show', pin %> 
     <% if pin.user == current_user %> 
     <%= link_to 'Edit', edit_pin_path(pin) %> 
     <%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure more than anything!?' } %></td> 
     <% end %> 
     </div> 
    <% end %> 
</div> 

Pins_controller.rb:

class PinsController < ApplicationController 
    before_action :authenticate_user!, except: [:index, :show] 
    before_action :correct_user, only: [:edit, :update, :destroy] 
    before_action :set_pin, only: [:show, :edit, :update, :destroy] 




    def index 
    @pins = Pin.all 
    end 


    def show 
    @pin = Pin.find params[:id] 
    end 


    def new 
    @pin = Pin.new 
    end 


    def edit 
    end 

    def create 
    @pin = Pin.new(pin_params) 
    if @pin.save 
     redirect_to @pin, notice: 'Pin was successfully created.' 
    else 
     render action: 'new' 
    end 
    end 




    def update 
     if @pin.update(pin_params) 
     redirect_to @pin, notice: 'Pin was successfully updated.' 
     else 
     render action: 'edit' 
     end 
    end 




    def destroy 
    @pin.destroy 
    redirect_to pins_url 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_pin 
     @pin = Pin.find(params[:id]) 
    end 

    def correct_user 
    @pin = current_user.pins.find(params[:id]) 
    redirect_to pins_path, notice: "Not allowed!" if @pin.nil? 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
def pin_params 
     params.require(:pin).permit(:description, :image) 
end 
end 

而且我的routes.rb文件

Rails.application.routes.draw do 
    resources :pins 
    devise_for :users 
    root "pages#home" 

    get "about" => "pages#about" 

end 
+1

请点击链接时使用查看确认吗?如果没有,这意味着您的页面上未启用rails-ujs库。 – MikDiet

+0

啊,不,我不知道。我会看看,现在感谢:) – Benjamints

回答

0

我的问题是,我没有列出“ jquery'在我的application.js

插入解决了我的问题。