我是新來的紅寶石。我想刪除記錄。但無法刪除。請檢查我的代碼 -數據沒有從sqlite3表中刪除
ruby_win_sources/index.html.erb
<table border="1" cellpadding="1" cellspacing="1" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Author</th>
<th>Url</th>
<th colspan="3">Action</th>
</tr>
</thead>
<tbody>
<% @ruby_win_sources.each do |ruby_win_source| %>
<tr>
<td><%= ruby_win_source.name %></td>
<td><%= ruby_win_source.author %></td>
<td><%= ruby_win_source.url %></td>
<td><%= link_to 'Show', ruby_win_source %></td>
<td><%= link_to 'Edit', edit_ruby_win_source_path(ruby_win_source) %></td>
<td><%= link_to 'Destroy', ruby_win_source, method: :destroy, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
ruby_win_sources_controller.rb
class RubyWinSourcesController < ApplicationController
before_action :set_ruby_win_source, only: [:show, :edit, :update, :destroy]
# GET /ruby_win_sources
# GET /ruby_win_sources.json
def index
@ruby_win_sources = RubyWinSource.all
end
# GET /ruby_win_sources/1
# GET /ruby_win_sources/1.json
def show
end
# GET /ruby_win_sources/new
def new
@ruby_win_source = RubyWinSource.new
end
# GET /ruby_win_sources/1/edit
def edit
end
# POST /ruby_win_sources
# POST /ruby_win_sources.json
def create
@ruby_win_source = RubyWinSource.new(ruby_win_source_params)
respond_to do |format|
if @ruby_win_source.save
format.html { redirect_to @ruby_win_source, notice: 'Ruby win source was successfully created.' }
format.json { render :show, status: :created, location: @ruby_win_source }
else
format.html { render :new }
format.json { render json: @ruby_win_source.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /ruby_win_sources/1
# PATCH/PUT /ruby_win_sources/1.json
def update
respond_to do |format|
if @ruby_win_source.update(ruby_win_source_params)
format.html { redirect_to @ruby_win_source, notice: 'Ruby win source was successfully updated.' }
format.json { render :show, status: :ok, location: @ruby_win_source }
else
format.html { render :edit }
format.json { render json: @ruby_win_source.errors, status: :unprocessable_entity }
end
end
end
# DELETE /ruby_win_sources/1
# DELETE /ruby_win_sources/1.json
def destroy
@ruby_win_source.destroy
respond_to do |format|
format.html { redirect_to ruby_win_sources_url, notice: 'Ruby win source was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_ruby_win_source
@ruby_win_source = RubyWinSource.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def ruby_win_source_params
params.require(:ruby_win_source).permit(:name, :author, :url)
end
end
刪除確認框不開放。
請幫我
編輯 - 的routes.rb
Rails.application.routes.draw do
resources :ruby_win_sources
end
你能夠插入和更新 – uzaif
是能插入並更新 – Chinmay235
你確定'link_to ... method::destroy'不應該是':delete'嗎?另外,更改'def destroy'來說''RubyWinSource.find(params [:id])。destroy' –