I am a beginner of Ruby on rails, I failed when I try to delete the object that I create. here is the code. controller
class PuzzlesController < ApplicationController
def index
@puzzles = Puzzle.all
end
def show
@puzzle=Puzzle.find(params[:id])
end
def new
@puzzle = Puzzle.new
end
def create
#render plain: params[:puzzle].inspect
@puzzle = Puzzle.new(puzzle_params)
if(@puzzle.save)
redirect_to @puzzle
else
render 'new'
end
end
def edit
@puzzle=Puzzle.find(params[:id])
end
def update
@puzzle=Puzzle.find(params[:id])
if(@puzzle.update(puzzle_params))
redirect_to @puzzle
else
render 'edit'
end
end
def destroy
@puzzle = Puzzle.find(params[:id])
@puzzle.destroy
redirect_to puzzle_path
end
private def puzzle_params
params.require(:puzzle).permit(:title,:body,:category,:difficulty)
end
end
<h2><%= @puzzle.title %></h2>
<p><%= @puzzle.body %></p>
<p><%= @puzzle.category %></p>
<p><%= @puzzle.difficulty %></p>
<hr>
<%= link_to "Edit", edit_puzzle_path(@puzzle), :class => 'btn btn-default'%>
<%= link_to "Delete", puzzle_path(@puzzle),
method: :delete,
data: {confrim: 'are you sure? '},
:class => 'btn btn-danger'%>
when i click on delete, its like re-render the page. i searched a lot on internet and cant find a solution for it.
this is the information on rails server.
Started GET "/puzzles/1" for ::1 at 2017-04-02 18:51:18 +0930
Processing by PuzzlesController#show as HTML
Parameters: {"id"=>"1"}
Puzzle Load (0.5ms) SELECT "puzzles".* FROM "puzzles" WHERE "puzzles"."id" = ? LIM IT ? [["id", 1], ["LIMIT", 1]]
Rendering puzzles/show.html.erb within layouts/application
Rendered puzzles/show.html.erb within layouts/application (1.0ms)
Completed 200 OK in 63ms (Views: 46.2ms | ActiveRecord: 0.5ms)