Question

I am building presentation builder, and I don't know how to destroy the chosen presentation presented in the list when I click on the button Remove.

My controllers looks like that:

  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

My list of created presentations looks like that:

  <% @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 %> 

My goal is: to write correct destroy method and create a link Remove that executes this method for a particular presentation.

Était-ce utile?

La solution

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

Something like that should do it.

More here http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html

Autres conseils

<%= link_to "Delete", your_destroy_path(p), method: :delete %>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top