我的網站遇到了一個問題,至少幾週來我一直在努力解決這個問題,所以我希望有人能夠指出我哪裡出了問題。對於一些背景知識,我是一名應屆畢業生,這是我為最終項目構建的頂點項目,在演示之前我沒有完全獲得我想要的所有功能,現在我已經完成了我正在嘗試的課程介紹一下我覺得缺少的功能。話雖這麼說,我用Rails 後端和帶有Bootstrap 主題的Vue 前端構建了一個恐怖電影願望清單,我可以將它添加到觀看列表中,並且可以將它們添加到喜愛的列表中或者討厭它的列表,但我最不想要的事情是,當您單擊按鈕將其添加到所述列表時,它會將其從未觀看的列表中刪除。我在後端設定了一個布林值,但對於我的生活,我無法得到正確的邏輯來讓它從true 翻轉到false 我不知道我是否需要前端的東西或什麼,但就像我說的我我們已經嘗試解決這個問題至少兩週了,所以任何幫助都會很棒。
我的架構
create_table "hatedits", force: :cascade do |t| t.integer "movie_id" t.integer "user_id" t.string "box_art" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end create_table "lists", force: :cascade do |t| t.integer "user_id" t.integer "movie_id" t.boolean "watched" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end create_table "lovedits", force: :cascade do |t| t.integer "movie_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.integer "user_id" t.string "box_art" end create_table "movies", force: :cascade do |t| t.string "name" t.string "description" t.string "box_art" t.string "sub_genre" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.integer "year" t.string "category" end create_table "users", force: :cascade do |t| t.string "name" t.string "email" t.string "password_digest" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end end
我的 Rails 更新和建立函數(我認為這就是問題所在,但我只是看不到它。)
def create list = List.create( user_id: current_user.id, movie_id: params[:movie_id], watched: false, ) if list.save render json: list else render json: {errors: list.errors.full_messages}, status: 406 end end def update list = List.find_by(id: params[:id]) list.movie_id = params[:movie_id] || list.movie_id if watched = true render json: list end if list.save render json: list else render json: {errors: list.errors.full_messages}, status: 406 end end
我的前端帶有移動到不同列表的按鈕和方法,這些按鈕和方法可以工作,但當電影移動到喜歡或討厭的列表時,不會將電影從未觀看的列表中刪除,
<template> <div class="list"> <br /> <br /> <br /> <br /> <br /> <section id="portfolio" class="portfolio"> <div class="container"> <div class="row portfolio-container"> <div class="col-lg-4 col-md-6 portfolio-item filter-app" v-for="list in lists" v-bind:key="list.id"> <div class="portfolio-wrap"> <img :src="`${list.movie.box_art}`" /> <br /> <div class="portfolio-info"> <div class="portfolio-links"> <button v-on:click="lovedIt(list)">Loved It</button> <br /> <br /> <button v-on:click="hatedIt(list)">Hated It</button> </div> </div> </div> </div> </div> </div> </section> </div> </template> <style> .list { text-align: center; color: white; } img { height: 624px; width: 370px; } </style> <script> import axios from "axios"; export default { data: function () { return { list: {}, lists: {}, movie: [], currentUser: localStorage.getItem("user_id"), }; }, created: function () { this.indexLists(); }, methods: { indexLists: function () { axios.get("/lists").then((response) => { this.lists = response.data; console.log("list", response.data); }); }, addMovie: function () { axios.post("/lists", this.movie).then(() => { this.$router.push("/lists"); }); }, lovedIt: function (list) { this.list = list; axios .post("/lovedits", { user_id: this.currentUser.id, movie_id: this.list.movie_id, }) .then(() => { console.log("yo"); this.$router.push("/lovedit"); location.reload(); }); }, hatedIt: function (list) { this.list = list; axios .post("/hatedits", { user_id: this.currentUser.id, movie_id: this.list.movie_id, }) .then(() => { console.log("sup"); this.$router.push("/hatedit"); location.reload(); }); }, }, }; </script>
您是否在此處的
if
語句中進行賦值而不是比較?