<% @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上为10.0.2.2开始获取“ / courses / 13”
由CoursesController#show处理为HTML
参数:{“ id” =>“ 13”}
课程负载(0.5ms)在“课程”中从“课程”中选择“课程”。“ id” = $ 1 LIMIT 1 [[“ id”,“ 13”]]
用户负载(0.5毫秒)从“用户”中选择“用户”。*从“用户”中查找“用户”。“ id” = 2由“用户”订购。“ id” ASC LIMIT 1
用户负载(0.5ms)选择“ users”。*从“ users”哪里“ users”。“ id” = $ 1 ORDER BY“ users”。“ id” ASC LIMIT 1 [[“ id”,2]]
课程存在(0.4ms)从“课程”中选择1作为“课程”中的内在联接“入学”。“ id” =“入学”。“ course_id”在“入学”中。“ user_id” = $ 1和“课程”。 “ id” = 13 LIMIT 1 [[“” user_id“,2]]
区段负载(1.0ms)从“ sections”中选择“ sections”。*从“ sections”到“ sections”。“ course_id” = $ 1 ORDER BY“ sections”。“ row_order” ASC [[“” course_id“,13]]
PG :: UndefinedColumn:错误:列sections.row_order不存在
第1行:...在“ WHERE” sections ..“ course_id” = $ 1 ORDER BY“ sections” ...
^
:SELECT“ sections”。*从“ sections”哪里“ sections”。“ course_id” = $ 1 ORDER BY“ sections ..” row_order“ ASC
在布局/应用程序中呈现的课程/show.html.erb(57.0毫秒)
在240毫秒内完成500个内部服务器错误
ActionView :: Template :: Error(PG :: UndefinedColumn:错误:列sections.row_order不存在
第1行:...在“ WHERE” sections ..“ course_id” = $ 1 ORDER BY“ sections” ...
^
::选择“ sections”。*从“ sections”哪里“ sections ..” course_id“ = $ 1 ORDER BY” sections ..“ row_order” ASC):
42:
43:
44:
45:
46:
47:
48:
app / views / courses / show.html.erb:45:在“ _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.0女士)
渲染的/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 / layout(19.6ms)
在2015-05-07 23:41:51 +0000上为10.0.2.2开始获取“ / courses / 13”
由CoursesController#show处理为HTML
参数:{“ id” =>“ 13”}
课程负载(0.5ms)在“课程”中从“课程”中选择“课程”。“ id” = $ 1 LIMIT 1 [[“ id”,“ 13”]]
用户负载(0.6毫秒)从“用户”中选择“用户”。*从“用户”中查找“用户”。“ id” = 2由“用户”订购。“ id” ASC LIMIT 1
用户负载(0.5ms)选择“ users”。*从“ users”哪里“ users”。“ id” = $ 1 ORDER BY“ users”。“ id” ASC LIMIT 1 [[“ id”,2]]
课程存在(0.3毫秒)从“课程”中选择1作为“课程”中的“加入”。 “ id” = 13 LIMIT 1 [[“” user_id“,2]]
区段负载(0.7ms)从“ sections”中选择“ sections”。*从“ sections”到“ sections”。“ course_id” = $ 1 ORDER BY“ sections”。“ row_order” ASC [[“” course_id“,13]]
PG :: UndefinedColumn:错误:列sections.row_order不存在
第1行:...在“ WHERE” sections ..“ course_id” = $ 1 ORDER BY“ sections” ...
^
:SELECT“ sections”。*从“ sections”到“ sections”。“ course_id” = $ 1 ORDER BY“ sections ..” row_order“ ASC
在布局/应用程序中呈现的课程/show.html.erb(51.8毫秒)
在163毫秒内完成500个内部服务器错误
ActionView :: Template :: Error(PG :: UndefinedColumn:错误:列sections.row_order不存在
第1行:...在“ WHERE” sections ..“ course_id” = $ 1 ORDER BY“ sections” ...
^
::选择“ sections”。*从“ sections”哪里“ sections ..” course_id“ = $ 1 ORDER BY” sections ..“ row_order” ASC):
42:
43:
44:
45:
46:
47:
48:
app / views / courses / show.html.erb:45:在“ _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.6女士)
渲染的/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 / layout(21.3ms)
最佳答案
我的直接猜测是您忘记了运行迁移,并且此列从未添加。您可以通过查看db / schema.rb文件来确认该列是否存在(并且已运行迁移)。
关于mysql - PG::UndefinedColumn:错误:列sections.row_order不存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30113478/