使用结束作为列名 [英] using end as column name

查看:328
本文介绍了使用结束作为列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保持一个滑轨2.1的应用程序,其中有对列名的一些不幸的选择。例如,一个事件都有一个开始和结束日期。而不是使用 start_at end_at 原设计用途启动结束。当然这将导致

 高清结束
    read_attribute(:结束)|| 1.hour.from_now
  结束
 

我很惊讶这甚至解析。这是合法的红宝石?真正的问题是,该局正在运行backgroundrb作业发送提醒邮件的时候吹了堆栈层次过深。模板是

 <%= [@ event.name,@ event.when_ pretty的,@ event.location,@ event.association,
 @ event.notes] .reject(安培;:?空白)*\ N%>
 

如果我deliver_reminder在控制台没有错误,但是当deliver_reminder是后台作业期间调用,发生错误。

问:我应该重构删除结束的方法,或者是堆栈错误所造成的其他东西。

在行#富/邮件/ reminder.rhtml

1

  1:<%= [@ event.name,@ event.when_ pretty的,@ event.location,@ event.association,@ event.notes] .reject (安培;:?空白)*\ N%>

LIB / virtual_attributes_and_associations.rb:59:在'virtual_attribute_names
LIB / virtual_attributes_and_associations.rb:83:在'read_attribute_without_virtual
LIB / virtual_attributes_and_associations.rb:86:在'read_attribute
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:2720:在'送'
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:2720:在'clone_attribute_value
供应商/轨/ ActiveRecord的/ lib目录/ active_record / dirty.rb:127:在'write_attribute
供应商/轨/ ActiveRecord的/ lib目录/ active_record / attribute_methods.rb:211:在'数据='
在'包括':LIB / virtual_attributes_and_associations.rb:9
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:177:在'呼'
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:177:在'evaluate_method
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:161:在'呼'
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:93:在'运行'
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:92:在'各'
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:92:在'送'
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:92:在'运行'
供应商/轨/的ActiveSupport / lib中/ active_support / callbacks.rb:272:在'run_callbacks
供应商/轨/ ActiveRecord的/ lib目录/ active_record / callbacks.rb:298:在'回调'
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:1450:在'送'
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:1450:在'实例化
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:582:在'的find_by_sql
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:582:在'收集'
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:582:在'的find_by_sql
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:1341:在'find_every
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:1376:在'find_one
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:1362:在'find_from_ids
供应商/轨/ ActiveRecord的/ lib目录/ active_record / base.rb:537:在'发现'
供应商/轨/ ActiveRecord的/ lib目录/ active_record /协会/ belongs_to_association.rb:44:在'find_target
供应商/轨/ ActiveRecord的/ lib目录/ active_record /协会/ association_proxy.rb:196:在'load_target
供应商/轨/ ActiveRecord的/ lib目录/ active_record /协会/ association_proxy.rb:99:在'重装'
供应商/轨/ ActiveRecord的/ lib目录/ active_record / associations.rb:1084:在'接触'
LIB / association.rb:52:在'associated_object
LIB / association.rb:48:在'联想'
供应商/轨/ ActiveRecord的/ lib目录/ active_record /协会/ association_proxy.rb:177:在'送'
供应商/轨/ ActiveRecord的/ lib目录/ active_record /协会/ association_proxy.rb:177:在`method_missing的'
应用程序/视图/富/邮件/ reminder.rhtml:1:`_run_erb_47app47views47foo47mailer47reminder46rhtml
 

解决方案

原来的问题是一个图书馆的方法叫做协会,当我改变了调用associated_object(这是由协会#协会呼吁),堆栈错误不再发生。

I'm maintaining a rails 2.1 application that has some unfortunate choices for column names. For instance, an Event has a start and an end date. Instead of using start_at and end_at the original design uses start and end. Of course this leads to

  def end
    read_attribute(:end) || 1.hour.from_now
  end

I'm surprised this even parses. Is this legal ruby? The real issue is that erb is blowing up with 'stack level too deep' when running a backgroundrb job to send the reminder emails. The template is

    <%= [@event.name, @event.when_pretty, @event.location, @event.association,
 @event.notes].reject(&:blank?) * "\n" %>

If I deliver_reminder in the console there is no error, but when deliver_reminder is called during the background job, the error occurs.

Question: should I refactor to remove the end method, or is the stack error being caused by something else?

On line #1 of foo/mailer/reminder.rhtml

1: <%= [@event.name, @event.when_pretty, @event.location, @event.association, @event.notes].reject(&:blank?) * "\n" %>

lib/virtual_attributes_and_associations.rb:59:in `virtual_attribute_names'
lib/virtual_attributes_and_associations.rb:83:in `read_attribute_without_virtual'
lib/virtual_attributes_and_associations.rb:86:in `read_attribute'
vendor/rails/activerecord/lib/active_record/base.rb:2720:in `send'
vendor/rails/activerecord/lib/active_record/base.rb:2720:in `clone_attribute_value'
vendor/rails/activerecord/lib/active_record/dirty.rb:127:in `write_attribute'
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:211:in `data='
lib/virtual_attributes_and_associations.rb:9:in `included'
vendor/rails/activesupport/lib/active_support/callbacks.rb:177:in `call'
vendor/rails/activesupport/lib/active_support/callbacks.rb:177:in `evaluate_method'
vendor/rails/activesupport/lib/active_support/callbacks.rb:161:in `call'
vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
vendor/rails/activesupport/lib/active_support/callbacks.rb:272:in `run_callbacks'
vendor/rails/activerecord/lib/active_record/callbacks.rb:298:in `callback'
vendor/rails/activerecord/lib/active_record/base.rb:1450:in `send'
vendor/rails/activerecord/lib/active_record/base.rb:1450:in `instantiate'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `collect!'
vendor/rails/activerecord/lib/active_record/base.rb:582:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:1341:in `find_every'
vendor/rails/activerecord/lib/active_record/base.rb:1376:in `find_one'
vendor/rails/activerecord/lib/active_record/base.rb:1362:in `find_from_ids'
vendor/rails/activerecord/lib/active_record/base.rb:537:in `find'
vendor/rails/activerecord/lib/active_record/associations/belongs_to_association.rb:44:in `find_target'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:196:in `load_target'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:99:in `reload'
vendor/rails/activerecord/lib/active_record/associations.rb:1084:in `contact'
lib/association.rb:52:in `associated_object'
lib/association.rb:48:in `association'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:177:in `send'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:177:in `method_missing'
app/views/foo/mailer/reminder.rhtml:1:in `_run_erb_47app47views47foo47mailer47reminder46rhtml'

解决方案

Turns out the issue was with a library method called association, when I changed that to call associated_object (which was called by Association#association), the stack error no longer occurred.

这篇关于使用结束作为列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆