jeudi 7 mai 2015

PG::UndefinedColumn: ERROR: column sections.row_order does not exist

<% @course.sections.rank(:row_order).each do |section| %>
    <br /><br />
        <div class="section">
            <h3>
                <%= section.title %>
            </h3>

I am getting undefined column for that row order in section. Here is my model for section...

class Section < ActiveRecord::Base
belongs_to :course
has_many :lessons

include RankedModel
ranks :row_order, :with_same => :course_id
end

Here is my migration.

class AlterSectionsAddRowOrder < ActiveRecord::Migration
  def change
    add_column :sections, :row_order, :integer
    add_index :sections, :row_order
  end
end

If this is of any use, here is the error message I get.

Started GET "/courses/13" for 10.0.2.2 at 2015-05-07 23:41:49 +0000 Processing by CoursesController#show as HTML Parameters: {"id"=>"13"} Course Load (0.5ms) SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", "13"]] User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1 User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]] Course Exists (0.4ms) SELECT 1 AS one FROM "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" WHERE "enrollments"."user_id" = $1 AND "courses"."id" = 13 LIMIT 1 [["user_id", 2]] Section Load (1.0ms) SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC [["course_id", 13]] PG::UndefinedColumn: ERROR: column sections.row_order does not exist LINE 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 Rendered courses/show.html.erb within layouts/application (57.0ms) Completed 500 Internal Server Error in 240ms

ActionView::Template::Error (PG::UndefinedColumn: ERROR: column sections.row_order does not exist LINE 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: <% @course.sections.rank(:row_order).each do |section| %> 46:

47: 48: app/views/courses/show.html.erb:45:in `_app_views_courses_show_html_erb___522001594__582727588'

Rendered /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) Rendered /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.9ms) Rendered /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 within rescues/layout (19.6ms)

Started GET "/courses/13" for 10.0.2.2 at 2015-05-07 23:41:51 +0000 Processing by CoursesController#show as HTML Parameters: {"id"=>"13"} Course Load (0.5ms) SELECT "courses".* FROM "courses" WHERE "courses"."id" = $1 LIMIT 1 [["id", "13"]] User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1 User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]] Course Exists (0.3ms) SELECT 1 AS one FROM "courses" INNER JOIN "enrollments" ON "courses"."id" = "enrollments"."course_id" WHERE "enrollments"."user_id" = $1 AND "courses"."id" = 13 LIMIT 1 [["user_id", 2]] Section Load (0.7ms) SELECT "sections".* FROM "sections" WHERE "sections"."course_id" = $1 ORDER BY "sections"."row_order" ASC [["course_id", 13]] PG::UndefinedColumn: ERROR: column sections.row_order does not exist LINE 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 Rendered courses/show.html.erb within layouts/application (51.8ms) Completed 500 Internal Server Error in 163ms

ActionView::Template::Error (PG::UndefinedColumn: ERROR: column sections.row_order does not exist LINE 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: <% @course.sections.rank(:row_order).each do |section| %> 46:

47: 48: app/views/courses/show.html.erb:45:in `_app_views_courses_show_html_erb___522001594__582727588'

Rendered /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) Rendered /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.3ms) Rendered /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 within rescues/layout (21.3ms)

Aucun commentaire:

Enregistrer un commentaire