SQLite3 :: SQLException:没有这样的列(Ruby on Rails)

时间:2018-04-04 21:03:05

标签: ruby-on-rails ruby activerecord

所以我正在尝试使用约会gem http://www.rubydoc.info/gems/appointments/1.3.3)。我完全按照文档说的那样完成,并且我不断收到以下错误:

ActiveRecord::StatementInvalid in AppointmentsController#index

SQLite3::SQLException: no such column: appointments.date: SELECT "appointments".* FROM "appointments" WHERE "appointments"."date" IS NULL

app/controllers/appointments_controller.rb:6:in `index'

schema.rb

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

  create_table "appointments", force: :cascade do |t|
    t.datetime "appointment_time"
    t.integer  "duration"
    t.float    "price"
    t.integer  "user_id"
    t.integer  "client_id"
    t.datetime "created_at",       null: false
    t.datetime "updated_at",       null: false
  end

  add_index "appointments", ["client_id"], name: "index_appointments_on_client_id"
  add_index "appointments", ["user_id"], name: "index_appointments_on_user_id"

  create_table "clients", force: :cascade do |t|
    t.string   "name"
    t.string   "phone_number"
    t.string   "email"
    t.string   "address"
    t.integer  "user_id"
    t.datetime "created_at",   null: false
    t.datetime "updated_at",   null: false
  end

  add_index "clients", ["user_id"], name: "index_clients_on_user_id"

  create_table "services", force: :cascade do |t|
    t.string   "name"
    t.string   "description"
    t.float    "price"
    t.integer  "duration"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
  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.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

end

appointments_controller.rb

class AppointmentsController < ApplicationController

  def index
    date_from_ajax = params[:matched_date]
    reduce = Appointment.where(:date => date_from_ajax)
    hour_on_date = reduce.collect {|x| x.hour}
    @new_dates = hour_on_date
    render :layout => false
  end

  def new
    @appointments = Appointment.create
      respond_to do |format|
        format.html
        format.js
        end
     end


  def create
     @appointment = Appointment.create(params[:appointments])
      if @appointment.save
        redirect_to new_appointment_path
      else
        err = ''
        @appointment.errors.full_messages.each do |m|
        err << m
      end

        redirect_to new_appointment_path, :flash => { :alert => "#{err}, please try again" }
      end
    end

  private

    def appointment_params
      params.require(:appointment).permit(:date, :hour, :done)
    end
end

appointments.rb

class Appointment < ActiveRecord::Base

validates :date,  :presence => true
validates :hour,  :presence => true,
                  :uniqueness => {:scope => :date}
end

有没有人可以帮我解决这个问题。

提前致谢:)

(Rails版本:4.2.6)

0 个答案:

没有答案