0

Wondering if someone can help me find this issue. I'm using rails 4, ruby 2, and have spent alot of time trying different accessors, etc and nothing has worked.

The whole plan model:

class Plan < ActiveRecord::Base
  has_many :users
end

Some of the user model:

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

Here's a pastebin of the whole users controller:

http://pastebin.com/GnXz3R8k

tmartin314
  • 4,061
  • 10
  • 39
  • 60
  • can you show the controller/action where the user it being created/updated. I am guessing the plan association is not being initialized when you are updating/creating the user. – tihom Sep 17 '13 at 22:32
  • I added a pastebin for the users controller – tmartin314 Sep 17 '13 at 23:28
  • try explicitly permitting `plan_attributes` in the `user_params` method like `plan_attributes: [:id, :price_tier]`. See [this](http://stackoverflow.com/questions/15919761/rails-4-nested-attributes-unpermitted-parameters). – tihom Sep 17 '13 at 23:45

1 Answers1

0

the migration was all messed up because of a superuser issue and it wasn't able to create the extensions for hstore field type.

tmartin314
  • 4,061
  • 10
  • 39
  • 60