不知道我在這裏與我的Rails應用程序丟失了什麼。我以非常相似的方式設立了「職位」和「項目」。但是,當我點擊我的「項目」鏈接時,我得到一個ActiveRecord :: Statement無效的錯誤。沒有這樣的問題與帖子索引頁面。具體的項目索引頁的信息是:獲取ActiveRecord :: Statement無效錯誤
「的SQLite3 ::的SQLException:沒有這樣的列:CREATED_BY:選擇 」項目工程 「ORDER BY CREATED_BY DESC」
我知道這往往是「 * FROM」。誤報事物造成的結果 - 特別是複數與單數需要匹配。儘管如此,這兩個模型和控制器對我來說也是一樣 - 只有很小的差異。所以我找不到問題所在。
這裏是我的控制器頁:
class ProjectsController < ApplicationController
before_action :find_project, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def index
@projects = Project.all.order("created_by DESC")
end
def new
@project = Project.new
end
def create
@project = Project.new project_params
if @project.save
redirect_to @project, notice: "Nice work! Successfully saved!"
else
render 'new'
end
end
def show
end
def edit
end
def update
if @project.update project_params
redirect_to @project, notice: "Nice work! That project was successfully updated!"
else
render 'edit'
end
end
def destroy
@project.destroy
redirect_to projects_path
end
private
def find_project
@project = Project.friendly.find(params[:id])
end
def project_params
params.require(:project).permit(:title, :description, :link, :slug)
end
end
而這裏的項目index.html.erb頁:
<h1 id="page_title">Projects</h1>
<div id="posts_wrapper" class="skinny_wrapper">
<% @projects.each do |project| %>
<div class="post">
<p class="date"><%= project.created_at.strftime('%A, %B, %d') %></p>
<h2><a href="#"><%= link_to project.title, project %></a></h2>
<hr>
</div>
<% end %>
</div>
這是我的_create_projects.rb表信息:
class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.string :title
t.text :description
t.string :link
t.timestamps null: false
end
end
我也有這個:
class AddSlugToProjects < ActiveRecord::Migration
def change
add_column :projects, :slug, :string
add_index :projects, :slug, unique: true
end
end
你在'projects'表'created_by'列? – Pavan
我會將表列信息添加到我原來的帖子中。 – Muirik
啊,是的沒有'created_by'列。檢查我的答案。 – Pavan