销毁链接路径不起作用

时间:2016-11-12 20:34:09

标签: ruby-on-rails ruby

我正在使用设计,我的销毁链接路径无法在我的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 个答案:

答案 0 :(得分:0)

我的问题是我没有在我的application.js

中列出'jquery'

插入解决了我的问题。