Reputation: 1368
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.
Upvotes: 0
Views: 138
Reputation: 181
<%= link_to "Delete", p, method: :delete %>
Something like that should do it.
More here http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
Upvotes: 1