没有路线匹配{:action =>“destroy”,:controller =>“links”}

时间:2013-03-12 14:47:38

标签: ruby-on-rails ruby-on-rails-3.2 routes

路由

   resources :links, only: [:new, :create, :index, :destroy]

links_conttroller

class LinksController < ApplicationController
before_filter :signed_in_user

def new
@user = current_user
@tags = @user.tags
@link = Link.new
end

def create
@link = Link.new(params[:link])
if @link.save
  flash[:success] = "Link created!"
  redirect_to root_url
else
  render 'new'
end
end

def index
@links = Link.paginate(page: params[:page])
end

def destroy
@link.destroy
redirect_to links_path
end

end

html.erb

<li>
<span class="location_info"> From Tag: <%= link.from_tag.ref %></span>
<span class="location_info"> To Tag: <%= link.to_tag.ref %></span>
<span class="location_info"> Cost: <%= link.value %>
| <%= link_to "delete", link, method: :delete,
                                 data: { confirm: "You sure?" } %></span>
</li>

为什么我收到此错误?

grep

1 个答案:

答案 0 :(得分:0)

你在github上的代码与你在这里的代码有所不同,但是, 你不需要首先找到destroy动作中的链接然后销毁它吗? 现在它在空destroy变量上调用@link

由于链接和路线看起来很好,我猜你应该像这样破坏行动:

def destroy
  @link= Link.find(params[:id])
  @link.destroy
  redirect_to links_path
end

除非你在应用程序的某处找到@link对象的过滤器。在github上更新你的代码,这样我就可以下载它并将其安装到我的计算机上,以便在上述解决方案无效的情况下进行更多调查。