0

我无法销毁具有有效路线的对象。浏览器返回No route matches [POST] "/blog/topics/3/posts/1". 但是,我可以对同一资源执行所有其他操作。鉴于我可以从控制台创建和销毁对象,我的控制器、模板应该如何?

节省时间 - 这些路线在我当前的配置下也不起作用:

这是我的控制器:

class Blog::PostsController < ApplicationController
  before_filter :fetch_topic, except: [:index]
  before_filter :fetch_post, except: [:create, :new]

  #stuff that works.
  ..
  ..
  ..

  def destroy
   @post.destroy
    respond_to do |format|
     format.html { redirect_to blog_topic_posts_url, notice: 'Post deleted.'}
    end
       #DOES NOT work: redirect_to root_url([:blog, @topic, @post]), notice: 'Post deleted.'
  end

  private  
   def fetch_post
    @post =  @topic.posts.find(params[:id]) 
   end

   def fetch_topic
    @topic = Topic.find(params[:topic_id])
   end

这是我的模板:

   <%= link_to 'Destroy', blog_topic_post_path(@topic, @post), method: :destroy, confirm: 'You Sure About This?' %>
4

2 回答 2

3

我认为您的 link_to 可能是错误的。查看RoR API的 link_to 选项应该是:method => :delete, :confirm => "Are you sure?".

此外,您的:fetch_post过滤器不会为 action 运行destroy,因此您不会有@postor @topic,因为:fetch_topic也不会被调用。

于 2012-02-16T18:24:55.800 回答
0

应该是method: :delete

于 2012-02-16T18:21:41.063 回答