0

나는 room이라는 모델을 가지고 있으며 쇼보기에서 다른 객실을 근처에 표시하고 싶습니다.postgresql을 사용하는 지오 코더 문제

show.html.erb

<div> 
    <% for room in @room.nearbys(10) %> 
    <%= image_tag room.photos[0].image.url(:medium) %> 
    <%= link_to room.listing_name, room %><br> 
    (<%= room.distance.round(2) %> miles away) 
    <% end %> 
</div> 

schema.rb는

ActiveRecord::Schema.define(version: 20161006135631) do 

    # These are extensions that must be enabled in order to support this database 
    enable_extension "plpgsql" 

    create_table "active_admin_comments", force: :cascade do |t| 
    t.string "namespace" 
    t.text  "body" 
    t.string "resource_id", null: false 
    t.string "resource_type", null: false 
    t.string "author_type" 
    t.integer "author_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree 
    t.index ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree 
    t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree 
    end 

    create_table "admin_users", force: :cascade do |t| 
    t.string "email",     default: "", null: 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.integer "sign_in_count",   default: 0, null: false 
    t.datetime "current_sign_in_at" 
    t.datetime "last_sign_in_at" 
    t.inet  "current_sign_in_ip" 
    t.inet  "last_sign_in_ip" 
    t.datetime "created_at",       null: false 
    t.datetime "updated_at",       null: false 
    t.index ["email"], name: "index_admin_users_on_email", unique: true, using: :btree 
    t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree 
    end 

    create_table "photos", force: :cascade do |t| 
    t.integer "room_id" 
    t.datetime "created_at",   null: false 
    t.datetime "updated_at",   null: false 
    t.string "image_file_name" 
    t.string "image_content_type" 
    t.integer "image_file_size" 
    t.datetime "image_updated_at" 
    t.index ["room_id"], name: "index_photos_on_room_id", using: :btree 
    end 

    create_table "rooms", force: :cascade do |t| 
    t.string "listing_name" 
    t.string "accommodation_type" 
    t.integer "persons" 
    t.integer "property" 
    t.integer "living_area" 
    t.text  "rooms_total" 
    t.text  "features_short" 
    t.string "pets" 
    t.string "smoking" 
    t.string "check_in" 
    t.string "check_out" 
    t.string "location" 
    t.text  "distance" 
    t.text  "features_long" 
    t.text  "detailed_description" 
    t.text  "house_rules" 
    t.string "address" 
    t.text  "video" 
    t.integer "nightly_price" 
    t.integer "hourly_price" 
    t.text  "detailed_price" 
    t.boolean "active" 
    t.datetime "created_at",   null: false 
    t.datetime "updated_at",   null: false 
    t.float "latitude" 
    t.float "longitude" 
    end 

    create_table "users", force: :cascade do |t| 
    t.string "email",     default: "", null: 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.integer "sign_in_count",   default: 0, null: false 
    t.datetime "current_sign_in_at" 
    t.datetime "last_sign_in_at" 
    t.inet  "current_sign_in_ip" 
    t.inet  "last_sign_in_ip" 
    t.datetime "created_at",       null: false 
    t.datetime "updated_at",       null: false 
    t.string "firstname" 
    t.string "lastname" 
    t.string "provider" 
    t.string "uid" 
    t.index ["email"], name: "index_users_on_email", unique: true, using: :btree 
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree 
    end 

    add_foreign_key "photos", "rooms" 
end 

나는 방향에 대한 RailsCasts Episode을 사용했다.

enter image description here

가 어떻게이 일을 할 수 있습니다 : 불행하게도 나는이 오류는 무엇입니까?

해결책에 대한 모든 의견을 보내 주시면 감사하겠습니다.

+0

schema.rb 파일을 게시 할 수 있습니까? – dnsh

+0

나는 schema.rb 정보를 가지고 나의 포스트를 편집했다. – trickydiddy

답변

1

rooms 테이블에는 거리 열이 있습니다.

SQL 쿼리에서 거리 (AS DISTANCE)이라는 별칭을 만듭니다.

따라서 PostgreSQL은 모호한 열 오류를 일으키고 있습니다.

이 쿼리는 당신은 내가 당신이 my_distance 또는 보석에 의해 생성 된 쿼리와 충돌하지 무언가처럼 뭔가에 열 거리의 열 이름을 변경하는 것이 좋습니다 사용하는 보석에 의해 생성됩니다.

+0

이것은 나를 위해 고마워! 제 SQL 쿼리가 별칭 DISTANCE를 만들고 있다는 것을 어떻게 알았습니까? 어쩌면 당신이 이걸 어떻게 알아 냈는지 알게되면 다음 번에 나 혼자서 알아낼 수 있습니다! 감사합니다;) – trickydiddy

+0

게시 한 스크린 샷에서 보았습니다. ** AS DISTANCE ** 절이있는 SQL 쿼리가 있습니다. – dnsh

+0

감사합니다. 감사합니다! – trickydiddy