i have created a new action using scaffold but when i click on the delete button, it displays the show page instead, My controller is
class CattleClientsController < ApplicationController
before_action :set_cattle_client, only: [:show, :edit, :update, :destroy]
# GET /cattle_clients
# GET /cattle_clients.json
def index
@cattle_clients = CattleClient.all
end
# GET /cattle_clients/1
# GET /cattle_clients/1.json
def show
end
# GET /cattle_clients/new
def new
@cattle_client = CattleClient.new
end
# GET /cattle_clients/1/edit
def edit
end
# POST /cattle_clients
# POST /cattle_clients.json
def create
@cattle_client = CattleClient.new(cattle_client_params)
logger.debug "New Cattle Client: #{@cattle_client.attributes.inspect}"
logger.debug "New Cattle Client should be valid: #{@cattle_client.valid?}"
respond_to do |format|
if @cattle_client.save
format.html { redirect_to @cattle_client, notice: 'Cattle client was successfully created.' }
format.json { render :show, status: :created, location: @cattle_client }
else
format.html { render :new }
format.json { render json: @cattle_client.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /cattle_clients/1
# PATCH/PUT /cattle_clients/1.json
def update
respond_to do |format|
if @cattle_client.update(cattle_client_params)
format.html { redirect_to @cattle_client, notice: 'Cattle client was successfully updated.' }
format.json { render :show, status: :ok, location: @cattle_client }
else
format.html { render :edit }
format.json { render json: @cattle_client.errors, status: :unprocessable_entity }
end
end
end
# DELETE /cattle_clients/1
# DELETE /cattle_clients/1.json
def destroy
@cattle_client.destroy
respond_to do |format|
format.html { redirect_to cattle_clients_url, notice: 'Cattle client was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_cattle_client
@cattle_client = CattleClient.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def cattle_client_params
params.require(:cattle_client).permit(:client_name, :milk, :date)
end
end
And my view page for the index is
<p id="notice"><%= notice %></p>
<h1 class="title">Listing Cattle Clients</h1>
<div class"btn-group menu2" align = right>
<%= link_to raw("<span class=''></span> Cattle"), cattles_path, :class=>"btn btn-default" %>
<%= link_to "Home", root_path, :class=>"btn btn-default" unless current_page?(root_url) %>
</div>
<table>
<thead>
<tr>
<th>Client name</th>
<th>Milk</th>
<th>Date</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @cattle_clients.each do |cattle_client| %>
<tr>
<td><%= cattle_client.client_name %></td>
<td><%= cattle_client.milk %></td>
<td><%= cattle_client.date %></td>
<td><%= link_to 'Show', cattle_client %></td>
<td><%= link_to 'Edit', edit_cattle_client_path(cattle_client) %></td>
<td><%= link_to 'Destroy', cattle_client, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Cattle client', new_cattle_client_path %>
Anyone help me identify why my delete button carries out the show action instead of deleting a column in the index page?