不会合作的布尔逻辑
Boolean logic that will not cooperate
我 运行 我的网站出现了一个问题,我现在已经为此苦苦思索了至少几周,所以我希望有人能指出我哪里出了问题。对于一些背景知识,我是一名应届毕业生,这是我为期末项目构建的顶点项目,在演示之前我并没有完全获得我想要的所有功能,现在我已经完成了 class 我正在尝试介绍我认为缺少的功能。话虽这么说,我构建了一个带有 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
语句中是赋值而不是比较?
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
我 运行 我的网站出现了一个问题,我现在已经为此苦苦思索了至少几周,所以我希望有人能指出我哪里出了问题。对于一些背景知识,我是一名应届毕业生,这是我为期末项目构建的顶点项目,在演示之前我并没有完全获得我想要的所有功能,现在我已经完成了 class 我正在尝试介绍我认为缺少的功能。话虽这么说,我构建了一个带有 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
语句中是赋值而不是比较?
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