nil的未定义方法`price_tier':NilClass

时间:2013-09-17 21:18:13

标签: ruby-on-rails ruby-on-rails-4

想知道是否有人可以帮我找到这个问题。我正在使用rails 4,ruby 2,并且花了很多时间尝试不同的访问器等,但没有任何工作。

整个计划模型:

class Plan < ActiveRecord::Base
  has_many :users
end

一些用户模型:

class User < ActiveRecord::Base
  ...
  validate :plan_type_valid
  belongs_to :plan
  ...

  def plan_type_valid
    if free_ok
      # the following line causes error
      valid_plans = Plan.where(price_tier: plan.price_tier).pluck(:id)
    else
      valid_plans = Plan.where(price_tier: plan.price_tier).where.not(stripe_id: 'free').pluck(:id)
    end
    unless valid_plans.include?(plan.id)
      errors.add(:plan_id, 'is invalid')
    end
  end
end

这是整个用户控制器的一个pastebin:

http://pastebin.com/GnXz3R8k

1 个答案:

答案 0 :(得分:0)

由于超级用户问题导致迁移全部搞砸了,并且无法为hstore字段类型创建扩展。

相关问题