如何解决500 内部服务器错误和未知属性
我被这个问题困住了。我在 index.html 文件中有一个 select 标记,但我不知道如何将它实现到架构中,或者我是否应该这样做。我正在开发一个应用程序,可以提醒事件。一对多的关系。任何帮助表示赞赏。随意问任何问题。谢谢。
控制台错误
{status: 500,error: "Internal Server Error",…}
error: "Internal Server Error"
exception: "#<ActiveModel::UnknownAttributeError: unknown attribute 'calendars' for Event.>"
status: 500
traces: {Application Trace: [{exception_object_id: 70106256841860,id: 9,…}],…}
listeners.js
document.addEventListener("DOMContentLoaded",function(e){
Calendar.all()
})
document.addEventListener('click',function(e) {
let target = e.target
if(target.matches(".selectCalendar")){
let calendar = Calendar.findById(target.dataset.calendarId)
calendar.show()
console.log("selected calendar",target.dataset)
}
})
document.addEventListener("submit",function(e){
let target = e.target
if(target.matches("#reminder_form")){
e.preventDefault();
let formData = {}
formData.name = target.name.value
formData.start_time = target.start_time.value
formData.end_time = target.end_time.value
formData.notes = target.notes.value
formData.calendars = target.calendars.value
formData.submit = target.submit_input.value
Event.create(formData)
return formData
}
})
架构
ActiveRecord::Schema.define(version: 2021_01_07_014444) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "calendars",force: :cascade do |t|
t.string "title"
t.bigint "user_id",null: false
t.datetime "created_at",precision: 6,null: false
t.datetime "updated_at",null: false
t.index ["user_id"],name: "index_calendars_on_user_id"
end
create_table "events",force: :cascade do |t|
t.string "name"
t.datetime "start_time"
t.datetime "end_time"
t.text "notes"
t.boolean "completed"
t.bigint "user_id",null: false
t.bigint "calendar_id",null: false
t.index ["calendar_id"],name: "index_events_on_calendar_id"
t.index ["user_id"],name: "index_events_on_user_id"
end
create_table "users",force: :cascade do |t|
t.string "email",default: "",null: false
t.string "encrypted_password",null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at",null: false
t.string "jti",null: false
t.index ["email"],name: "index_users_on_email",unique: true
t.index ["jti"],name: "index_users_on_jti",unique: true
t.index ["reset_password_token"],name: "index_users_on_reset_password_token",unique: true
end
add_foreign_key "calendars","users"
add_foreign_key "events","calendars"
add_foreign_key "events","users"
end
**index.html**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Reminders Project</title>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
crossorigin="anonymous" />
</head>
<body>
<div class="container mx-auto sm:grid grid-cols-3 gap-4 my-4">
<section id="flash" class="bg-red-200 h-10 col-span-3 py-2 pl-4 opacity-0 transition-opacity duration-700">Error Message</section>
<section id="calendarListsContainer" class="px-4 bg-blue-100 sm:min-h-screen rounded-md shadow">
<form id="reminder_form" class="px-4 bg-blue-100 sm:min-h-screen rounded-md shadow">
<h1><strong>Reminder Form</strong></h1>
<fieldset class="my-1">
<label for="Title">Title</label> <br />
<input type="text" class="w-full" name="title_input" />
</fieldset>
<fieldset class="my-1">
<label for="notes">Notes</label> <br />
<textarea name="notes_input" id="notes" class="w-full h-16"></textarea>
</fieldset>
<fieldset class="my-1">
<label for="DateTime">Start Time</label> <br />
<input type="datetime-local" name="start_time" id="datetime" class="w-full" />
</fieldset>
<fieldset class="my-1">
<label for="DateTime">End Time</label> <br />
<input type="datetime-local" name="end_time" id="datetime" class="w-full" />
</fieldset>
<fieldset class="my-1">
<label for="calendars">Choose a Calendar:</label>
<select name="calendars" id="calendars">
<option value="personal">Personal</option>
<option value="work">Work</option>
<option value="private">Private</option>
</select>
</fieldset>
<input type="submit" value="submit" name="submit_input" class="block w-full mt-2 bg-black text-white" />
</form>
</section>
<section id="eventContainer" class="px-4 bg-blue-100 sm:min-h-screen col-span rounded-md shadow">
<h1 class="text-2xl font-semibold border-b-4 border-blue-300">
Events
</h1>
<form id="newEvent" class="flex mt-4">
<input type="text" class="block flex-1 p-3" placeholder="New Event" />
<button type="submit" class="block flex-none">
<i class="fa fa-plus p-4 z-auto bg-green-400"></i>
</button>
</form>
<ul id="events" class="list-none">
<li class="my-2 px-4 bg-green-200 grid grid-cols-12">
<a href="#" class="py-4 col-span-10">My First Event</a>
<a href="#" class="my-4 text-right"><i class="fa fa-pencil-alt"></i></a>
<a href="#" class="my-4 text-right"><i class="fa fa-trash-alt"></i></a>
</li>
</ul>
</section>
</div>
<script src="js/models.js"></script>
<script src="js/listeners.js"></script>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。