0

我正在构建演示文稿生成器,当我单击“删除”按钮时,我不知道如何销毁列表中显示的所选演示文稿。

我的控制器看起来像这样:

  def create
    if logged_in?
      presentation = current_user.presentations.create data: params.to_yaml
      redirect_to edit_presentation_path(presentation)
    end
  end

  def edit
    render action: :new
  end

  # def destroy
  #   current_presentation.destroy
  # end

  def show
    render action: :new
  end

  def list
    @presentations = current_user.presentations
  end

  def update
    current_presentation.update_attributes(data: params.to_yaml)
  end

  def home
    if logged_in?
      @presentations = current_user.presentations
    end
  end

我创建的演示文稿列表如下所示:

  <% @presentations.each do |p| %> 
      <a >  <%= p.id %>
        <a href="<%= presentation_path(p) %>" target="_blank" class="action"> Show </a> 
        <a class="action"> Remove </a>  
      </a>
   <% end %> 

我的目标是:编写正确的销毁方法并创建一个链接删除,该链接为特定的演示文稿执行此方法。

4

2 回答 2

1
<%= link_to "Delete", p, method: :delete %>

应该这样做。

更多这里http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html

于 2013-10-24T16:11:45.630 回答
1
<%= link_to "Delete", your_destroy_path(p), method: :delete %>
于 2013-10-24T16:18:18.167 回答