You are missing a comma between 'Delete' recipes
in the arguments list:
<%= link_to 'Delete', recipes, method: :delete %>
Which solves the syntax error. However placing an <a>
inside a <button>
tag is invalid HTML.
Permitted content
Phrasing content but there must be no Interactive content
- MDN Web Docs: The Button element
Either just style a regular <a>
with CSS to look like a button or create a discrete form with button_to
:
<%= button_to 'Delete', recipes, method: :delete %>
Since you seem to be just flailing around you can get an example of the how to actually code this by running the scaffold generator.
$ rails g scaffold recipe title:string
Which generates:
# config/routes.rb
Rails.application.routes.draw do
resources :recipes
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
# app/controllers/recipes_controller.rb
class RecipesController < ApplicationController
before_action :set_recipe, only: [:show, :edit, :update, :destroy]
# GET /recipes
# GET /recipes.json
def index
@recipes = Recipe.all
end
# ...
# DELETE /recipes/1
# DELETE /recipes/1.json
def destroy
@recipe.destroy
respond_to do |format|
format.html { redirect_to recipes_url, notice: 'Recipe was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_recipe
@recipe = Recipe.find(params[:id])
end
# ...
end
# app/views/recipes/index.html.erb
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @recipes.each do |recipe| %>
<tr>
<td><%= link_to 'Show', recipe %></td>
<td><%= link_to 'Edit', edit_recipe_path(recipe) %></td>
<td><%= link_to 'Destroy', recipe, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
Note that in Rails proper pluralization is very important as it ties in with the whole convention over configuration approach.