Rails削除機能について

前提

インスタのような写真投稿を作成しています。
削除機能が実装できません。

実現したいこと

ここに実現したいことを箇条書きで書いてください。
Myぺージ[Show]に自分の投稿した一覧が表示され、
右2列に編集機能と削除機能がある。

発生している問題・エラーメッセージ

削除機能について
リンク先の数字が変わるだけで削除されない。

エラーメッセージ

エラーメッセージも特に出ない

該当のソースコード

ソースコード 【コントローラー】 def edit @album = Album.find(params[:id]) end def update @album = Album.find(params[:id]) @album.update(album_params) flash[:notice] = "Updated!" redirect_to user_path end def destroy album_del = Album.find(params[:id]) if album_del.destroy redirect_to root_path, notice: "削除が完了しました" else redirect_to root_path, alert: "削除が失敗しました。" end end private def album_params params.require(:album).permit(:title, :message, :image) end 【View:Show】 <div class="container-fluid"> <div class="row album-index-row"> <div class="col-lg-3 side-border"> <%= render 'share/sidemenu' %> </div> <div class="col-lg-9 top-border"> <h3>Picture Contribution</h3> <table class="table table-striped"> <tr> <th>Contributor</th> <th>Title</th> <th>Edit</th> <th>Destroy</th> </tr> <% @album.each do |album| %> <tr> <td> <%= link_to user_path(album.user_id) do %> <%= image_tag album.user.profile_image.url, size: '70x70' %><br> <%= album.user.name %> <% end %> </td> <td> <%= link_to album_path(album.id) do %> <%= album.title %> <% end %> </td> <td> <%= link_to edit_album_path(album.id) do %> Edit <% end %> </td> <td> <%= link_to album_path(album), method: :delete do %> Destroy <% end %> </td> </tr> <% end %> </table> </div> </div> </div> 【モデル】 class Album < ApplicationRecord belongs_to :user mount_uploader :image, ImageUploader end class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable mount_uploader :profile_image, ProfileImageUploader has_many :album, dependent: :destroy end 【データベース】 create_table "albums", force: :cascade do |t| t.string "title" t.string "message" t.string "comment" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "image" t.integer "user_id" t.string "image_id" end create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "sex" t.string "introduction" t.string "profile_image" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end 【Routes】 Rails.application.routes.draw do devise_for :users root :to => 'albums#index' resources :users, only: [:index, :edit, :update, :show, :destroy] resources :albums, only: [:new, :create, :index, :show, :edit, :update, :destroy] get 'detail/:id' => 'albums#detail', as: 'detail_album' end

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

コメントを投稿

0 コメント