【发布时间】:2015-07-18 18:12:26
【问题描述】:
<% @course.sections.rank(:row_order).each do |section| %>
<br /><br />
<div class="section">
<h3>
<%= section.title %>
</h3>
我在部分中获得了该行顺序的未定义列。这是我的部分模型...
class Section < ActiveRecord::Base
belongs_to :course
has_many :lessons
include RankedModel
ranks :row_order, :with_same => :course_id
end
这是我的迁移。
class AlterSectionsAddRowOrder < ActiveRecord::Migration
def change
add_column :sections, :row_order, :integer
add_index :sections, :row_order
end
end
如果这有任何用处,这是我收到的错误消息。
在 2015-05-07 23:41:49 +0000 开始 GET "/courses/13" for 10.0.2.2 CoursesController 处理#show as HTML 参数:{"id"=>"13"} 课程负载 (0.5ms) SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", "13"]] 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]] 课程存在(0.4 毫秒)从“课程”内部加入“注册”中选择 1 个“课程”。“id”=“注册”。“course_id”其中“注册”。“user_id”= $1 和“课程”。 "id" = 13 限制 1 [["user_id", 2]] 部分负载(1.0ms)选择“sections”。* FROM “sections” WHERE “sections”。“course_id” = $1 ORDER BY “sections”.“row_order” ASC [[“course_id”, 13]] PG::UndefinedColumn: 错误: 列sections.row_order 不存在 第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"... ^ : SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC 在布局/应用程序中渲染课程/show.html.erb (57.0ms) 在 240 毫秒内完成 500 个内部服务器错误
ActionView::Template::Error (PG::UndefinedColumn: ERROR: columnsections.row_order 不存在
第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"...
^
: SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC):
42:
43:
44:
45:
46:
47:
48:
app/views/courses/show.html.erb:45:in `_app_views_courses_show_html_erb___522001594__582727588'
渲染/home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_trace。 erb (2.0ms) 渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.9小姐) 在救援中渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb /布局(19.6 毫秒)
在 2015-05-07 23:41:51 +0000 开始 GET "/courses/13" for 10.0.2.2 CoursesController 处理#show as HTML 参数:{"id"=>"13"} 课程负载 (0.5ms) SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", "13"]] 用户负载 (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1 用户负载 (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]] 课程存在(0.3 毫秒)从“课程”中选择 1 个作为一个,在“课程”中加入“注册”。“id”=“注册”。“课程 ID”在哪里“注册”。“用户 ID”=1 美元和“课程”。 "id" = 13 限制 1 [["user_id", 2]] 部分负载(0.7ms)选择“sections”。* FROM “sections” WHERE “sections”。“course_id” = $1 ORDER BY “sections”.“row_order” ASC [[“course_id”, 13]] PG::UndefinedColumn: 错误: 列sections.row_order 不存在 第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"... ^ : SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC 在布局/应用程序中渲染课程/show.html.erb (51.8ms) 在 163 毫秒内完成 500 个内部服务器错误
ActionView::Template::Error (PG::UndefinedColumn: ERROR: columnsections.row_order 不存在
第 1 行:...ons" WHERE "sections"."course_id" = $1 ORDER BY "sections"...
^
: SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC):
42:
43:
44:
45:
46:
47:
48:
app/views/courses/show.html.erb:45:in `_app_views_courses_show_html_erb___522001594__582727588'
渲染/home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_trace。 erb (3.6ms) 渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.3小姐) 在救援中渲染 /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb /布局(21.3 毫秒)
【问题讨论】:
-
您忘记运行迁移了吗?
标签: mysql ruby-on-rails ruby-on-rails-3 migration