Я получаю следующую ошибку в приложении Rails.Вы можете мне помочь?
Я получаю сообщение об ошибке при соединении двух таблиц.Пользователь хочет использовать таблицу.Я пытаюсь управлять полями идентификатора менеджера и идентификатора пользователя из одной таблицы.
ruby 2.5.1p57 (версия 20130-03-29 63029) [x86_64-darwin17]
Rails 5.2.2
Разработка базы данных
Сообщение об ошибке
Разработка базы данных и таблиц схема.rb:
ActiveRecord::Schema.define(version: 2019_02_24_160401) do
create_table "projects", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.text "description"
t.string "company"
t.bigint "manager_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["manager_id"], name: "index_projects_on_manager_id"
end
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "username", default: "", null: false
t.string "fullname", default: ""
t.bigint "manager"
t.string "company", default: ""
t.string "department", default: ""
t.boolean "isadmin", default: 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.datetime "created_at", null: false
t.datetime "updated_at", null: false
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
add_foreign_key "projects", "users", column: "manager_id"
end
projects_controller.rb
class ProjectsController < ApplicationController
before_action :set_project, only: [:show, :edit, :update, :destroy]
before_action :find_users, only: [:index, :show, :new, :edit]
# GET /projects
# GET /projects.json
def index
@projects = Project.all
end
# GET /projects/1
# GET /projects/1.json
def show
end
# GET /projects/new
def new
@project = Project.new
end
# GET /projects/1/edit
def edit
end
# POST /projects
# POST /projects.json
def create
@project = Project.new(project_params)
respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was successfully created.' }
format.json { render :show, status: :created, location: @project }
else
format.html { render :new }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /projects/1
# PATCH/PUT /projects/1.json
def update
respond_to do |format|
if @project.update(project_params)
format.html { redirect_to @project, notice: 'Project was successfully updated.' }
format.json { render :show, status: :ok, location: @project }
else
format.html { render :edit }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
# DELETE /projects/1
# DELETE /projects/1.json
def destroy
@project.destroy
respond_to do |format|
format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_project
@project = Project.find(params[:id])
end
def find_users
@users = User.all.order('created_at desc')
end
# Never trust parameters from the scary internet, only allow the white list through.
def project_params
params.require(:project).permit(:name, :description, :user_id)
end
end
Файлы модели в папке модели project.rb и user.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
has_many :projects
end
class Project < ApplicationRecord
belongs_to :user
end
вызов столбца электронной почты моего кода index.html.erb
<p id="notice"><%= notice %></p>
<h1>Projects</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Company</th>
<th>Manager</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @projects.each do |project| %>
<tr>
<td><%= project.name %></td>
<td><%= project.description %></td>
<td><%= project.company %></td>
<td><%= project.user.email %></td>
<td><%= link_to 'Show', project %></td>
<td><%= link_to 'Edit', edit_project_path(project) %></td>
<td><%= link_to 'Destroy', project, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Project', new_project_path %>