i have created new action using scaffold when click on delete button, displays show page instead, controller is
class cattleclientscontroller < applicationcontroller before_action :set_cattle_client, only: [:show, :edit, :update, :destroy] # /cattle_clients # /cattle_clients.json def index @cattle_clients = cattleclient.all end # /cattle_clients/1 # /cattle_clients/1.json def show end # /cattle_clients/new def new @cattle_client = cattleclient.new end # /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 valid: #{@cattle_client.valid?}" respond_to |format| if @cattle_client.save format.html { redirect_to @cattle_client, notice: 'cattle client 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 |format| if @cattle_client.update(cattle_client_params) format.html { redirect_to @cattle_client, notice: 'cattle client 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 |format| format.html { redirect_to cattle_clients_url, notice: 'cattle client destroyed.' } format.json { head :no_content } end end private # use callbacks share common setup or constraints between actions. def set_cattle_client @cattle_client = cattleclient.find(params[:id]) end # never trust parameters scary internet, allow white list through. def cattle_client_params params.require(:cattle_client).permit(:client_name, :milk, :date) end end and view page 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 |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 sure?' } %></td> </tr> <% end %> </tbody> </table> <br> <%= link_to 'new cattle client', new_cattle_client_path %> anyone me identify why delete button carries out show action instead of deleting column in index page?
please try :method => :delete
also sure jquery-rails has been installed , following code in head tags
<%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
Comments
Post a Comment