Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

gov_uk_date_field in non-ActiveRecord class #15

Open
lostie opened this issue Nov 8, 2016 · 2 comments
Open

gov_uk_date_field in non-ActiveRecord class #15

lostie opened this issue Nov 8, 2016 · 2 comments

Comments

@lostie
Copy link

lostie commented Nov 8, 2016

I'm trying to use this helper in a form class which is not particularly tied to an ActiveRecord class and I'm getting the following error:

NoMethodError - undefined method `after_initialize' for Forms::Search:Class:
   () Users/username/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/gov_uk_date_fields-8694009d8e08/lib/gov_uk_date_fields/acts_as_gov_uk_date.rb:17:in `acts_as_gov_uk_date'

Is it possible to provide support for this helper outside the scope of an ActiveRecord?

@StupidCodeFactory
Copy link

PVB team also need to use this with non ActiveRecord::Base model

@zheileman
Copy link
Member

I'm a bit late to the party but for a Family Justice project I've made this gem works with non-AR models. In case it is useful this is the specific PR implementing a date field in a non-AR object:

ministryofjustice/c100-application#23

The main reason why it was not working is because non-AR models doesn't implement callbacks out of the box. But you can extend your model to use callbacks.

Also, so the gem works out of the box, the methods [] and []= must be re-implemented in your model. This is because the gem uses in a couple places this syntax to have direct access to attributes bypassing getter/setter. Ideally the gem shouldn't rely on these methods so it is less coupled to AR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants