I am building a mock up of reddit. When on my show view that displays the link & title I submit I have included an option(link) to destroy the submission.
When I click on the destroy I get:
ActionController::ParameterMissing in LinksController#destroy
param not found: link
on line:
params.require(:link).permit(:url, :title)
This is my full Links controller:
class LinksController < ApplicationController
def index
@link = Link.all
end
def show
@link = Link.find(params[:id])
end
def new
@link = Link.new
end
def create
@link = Link.new(link_params)
if @link.save
redirect_to @link
else
render action: 'new'
end
end
def destroy
@link = Link.find()
if @link.destroy
redirect_to index: 'action'
else
render show: 'action'
end
end
private
def link_params
params.require(:link).permit(:url, :title)
end
end
This is my show view:
<h1> This is the show view </h1>
<%= @link.title %>
<%= @link.url %>
<%= link_to 'Edit', edit_link_path(@link) %>\
<%= link_to 'Destroy', (@link), method: :delete, data: { confirm: 'Are you sure?' } %>
I'm really confused, have tried multiple things but can't get it to work. How can i fix this?
Looks like you permit is missing :id and your destroy is missing params[:id] in the find clause.