Ruby on rails “脚手架删除”按钮显示“显示”页面

Ruby on rails “脚手架删除”按钮显示“显示”页面,ruby-on-rails,scaffolding,Ruby On Rails,Scaffolding,我使用scaffold创建了一个新操作,但当我单击delete按钮时,它会显示show页面, 我的控制器是 class CattleClientsController < ApplicationController before_action :set_cattle_client, only: [:show, :edit, :update, :destroy] # GET /cattle_clients # GET /cattle_clients.json def ind

我使用scaffold创建了一个新操作,但当我单击delete按钮时,它会显示show页面, 我的控制器是

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
我的索引查看页面是

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

有人帮我确定为什么我的删除按钮执行显示操作而不是删除索引页中的列吗?

请尝试:方法=>:删除

还要确保jQueryRails已经正确安装,并且您的头标签中有以下代码

         <%= javascript_include_tag :defaults %>
         <%= csrf_meta_tag %>

您能否在服务器日志中验证该操作的类型为DELETE…,而不是GET?我的意思是说,这是删除请求还是获取请求?我怀疑您的路由不匹配。你能检查一下耙子路线并给出一些反馈吗。另外,请检查是否正确安装了jquery rails。哦,当我使用rake routes进行检查时,它表明它是一个删除请求,没有jquery rails gem,现在已经安装了,但没有yetAs Milind建议的更改,请查看终端/命令行中的服务器,并查看当您单击删除按钮时它会显示什么。我建议首先通过键入command-k MAC或ctrl-k PC来清除它。然后单击delete并查看发生的路由和操作。