2016-04-06 15 views
0

ruby​​が新しくなりました。私はレコードを削除したい。しかし、削除することはできません。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 

削除の確認ボックス開いていない - 私のコードを確認してください。

編集私を助けてください - あなたはあなたのデータベースrake db:dropをドロップして、ANを破壊しながら、deleteリクエストを行い、あなたのテーブル

+0

あなたは – uzaif

+0

にはいことを挿入して更新することができます挿入と更新 – Chinmay235

+1

あなたは 'link_to ... method::destroy'が':delete'ではないと確信していますか?また、 'RubyWinSource.find(params [:id])。destroy'と言うように' def destroy'を変更してください。 –

答えて

0

オブジェクト:

<td><%= link_to 'Destroy', ruby_win_source, method: :delete, data: { confirm: 'Are you sure?' } %></td> 
あなたはあなたがすでに実行されます @ruby_win_sourceアクション destroy前に持って

before_action :set_ruby_win_source, only: [:show, :edit, :update, :destroy] 

を設定しているので、

お使いのコントローラがよさそうです。

+0

これはこの問題と何が関係していますか? –

+0

私のデータベースは正常に動作しています。私は追加、更新、ビューを正常に完了しました。しかし、問題はRecord not deletedです。 – Chinmay235

0

を作成するdb:migrateを熊手 routes.rbを

Rails.application.routes.draw do 
    resources :ruby_win_sources 
end 
0

私は削除するかのlink_toが間違っていると、このようにすべきだと思います。

<%= link_to 'Destroy', ruby_win_source, method: :delete, data: { confirm: 'Are you sure?' } %> 

その後に自分のコントローラdestroyメソッドを更新:

# DELETE /ruby_win_sources/1 
# DELETE /ruby_win_sources/1.json 
def destroy 
    RubyWinSource.find_by_id(params[:id]).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 
+0

私のコメントのようなビット、または@ dkpからのその答え! –

+0

あなたのコードを確認してください。 – Chinmay235

+0

同じ問題はありません。破棄リンクをクリックしている間*削除確認ボックス*は来ない。ページをビューページにリダイレクトします。 – Chinmay235

関連する問題