Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default values aren't assigned when initialize method is present. #373

Open
prasadsurase opened this issue Apr 3, 2017 · 1 comment
Open

Comments

@prasadsurase
Copy link

I am using rails 5.0.2 with virtus 1.0.5. I have a form defined as below

class MyForm
  include Virtus.model

  attribute :age, Integer, default: 0
  attribute :birthday, DateTime, default: :some_date
  attribute :salutation, String, default: 'Mr.'

  def initialize
  end

  private

  def some_date
    Date.today - 3.years
  end
end

If the initialize method is removed, the default values are present when an instance of MyForm is created. The values are absent if the initialize is present.

@prasadsurase prasadsurase changed the title Default values aren't assigned when initialize method is defined. Default values aren't assigned when initialize method is present. Apr 3, 2017
@joshmn
Copy link

joshmn commented Apr 25, 2017

Did you try passing you pass lazy => true to your attribute?

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

No branches or pull requests

2 participants