繁体   English   中英

Heroku-ActiveRecord :: StatementInvalid(PG :: Error:ERROR:列“ requested”不存在

[英]Heroku - ActiveRecord::StatementInvalid (PG::Error: ERROR: column “requested” does not exist

我有一个absense.html.erb ,可以在开发和生产中正常工作。 但是,当我尝试访问页面时,出现以下错误:

2013-03-25T18:43 + 00:00 app [web.1]:在2013-03-25 18:43:43 +0000 2013-03-25T18:43开始针对77.100.90.77的GET“ /缺席” :43 + 00:00 app [web.1]:2013-03-25T18:43:43 + 00:00 app [web.1]:ActiveRecord :: StatementInvalid(PG :: Error:错误:ERROR:列“ requested”做了不存在2013-03-25T18:43:43 + 00:00 app [web.1]:第1行:...尊敬的“假期”。*来自“假期”的地方(状态=“要求... 2013-03 -25T18:43:43 + 00:00 app [web.1]:
^ 2013-03-25T18:43:43 + 00:00 app [web.1]::选择“假日”。*从“假日”位置(状态=“要求”)):2013-03-25T18:43: 43 + 00:00 app [web.1]:2013-03-25T18:43:43 + 00:00 app [web.1]:2013-03-25T18:43:43 + 00:00 app [web.1 ]:
app / controllers / holidays_controller.rb:52:in'absence'2013-03-25T18:43:43 + 00:00 heroku [router]:at = info method = GET path = / rota_days host = miuk-portal.herokuapp。 com fwd =“ 77.100.90.77” dyno = web.1队列= 0等待= 0ms连接= 1ms服务= 5773ms状态= 200字节= 897173

错误指向控制器中我的弃权方法的以下行

def absence
#show the holidays where the approver id matches the current user id
#and state = "requested"'

    @user = current_user
    if current_user.role? :administrator
      # a superadmin can view all current holiday requests
      @holidays = Holiday.find(:all, :conditions => 'state = "requested"')
    else
      #otherwise an admin sees the holiday requests that they are approvers for
      @holidays = Holiday.find(:all, :conditions => ["approver_id = #{current_user.id}", "state = requested"])
    end
  end

我已经在假期模型中声明了这一点,如下所示:

Holiday.rb

class Holiday < ActiveRecord::Base

  belongs_to :user
  belongs_to :calendar
  belongs_to :type, :class_name => "Type"
  belongs_to :approver, :class_name => "User"


  before_create :default_values #Before creating holiday set default_values
                                #before_create :overflow


  validates :start_at, :presence => { :message => "must be a valid date/time" }
  validates :end_at, :presence => {:message => "must be a valid date/time"}
  validate :start_must_be_before_end_date
  validate :overflow #Hook method to determine if user holidays are over the set amount
  validates_presence_of :end_at, :start_at

  attr_accessible :description, :end_at, :start_at, :state, :type_id, :user_id, :color


  def length
    (self.end_at.to_i - self.start_at.to_i)/(60*60*24)
  end

  def days_used
    ( (start_at.to_date)..(end_at.to_date) ).select {|d| (1..5).include?(d.wday) }.size
  end


  #Validates_presence_of is called to ensure that the start date exisit.
  #Start date must be lt or = to end date otherwise throw error.
  def start_must_be_before_end_date
    errors.add(:start_at, "must be before end date") unless
        self.start_at <= self.end_at
  end

  #Overflow of holidays is validated by calling "validates" L31. Then checks if absent days
  #Is gt or = to length
  def overflow
    errors.add(:overflow, "- You only have #{user.absentdays} days holiday remaining; this absence is #{length} days.") unless
        user.absentdays >= length
  end

  def name
    return self.user.name
  end

  def colors
    if state ||= "denied"
      return self.color ||= "#C00000"

    end
  end

  private

  #Setting default values - before_create is called and sets the following
  def default_values
    self.state ||= "requested"
    self.color ||= "#000000"
    self.type_id||= 1
  end
end

似乎不明白为什么这会同时在开发和生产中起作用,而不是在heroku中起作用。 有任何想法吗?

标准SQL字符串使用单引号,双引号用于标识符(例如表名和列名); PostgreSQL遵循这里的标准,MySQL和SQLite不太严格,其他数据库则以不同的严格程度执行其他操作。 无论如何,SQL字符串文字的单引号在任何地方都应相同。

您在SQL字符串上使用双引号:

@holidays = Holiday.find(:all, :conditions => 'state = "requested"')
#------------------------------------------------------^---------^

您必须使用单引号:

@holidays = Holiday.find(:all, :conditions => %q{state = 'requested'})

或对其进行现代化处理,然后让ActiveRecord处理以下引用:

@holidays = Holiday.where(:state => 'requested')

您可能还需要修复此报价单:

@holidays = Holiday.find(:all, :conditions => ["approver_id = #{current_user.id}", "state = requested"])

同样,现代化是最简单的方法:

@holidays = Holiday.where(:approver_id => current_user.id, :state => 'requested')

我猜想您是在SQLite上进行开发,但在PostgreSQL上进行部署。 这是一个坏主意,始终在同一堆栈上进行开发和部署。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM