minsk-hackerspace / hackerspace.by

Website of Minsk Hackerspace (Ruby on Rails)
https://hackerspace.by/
11 stars 20 forks source link

Set full tariff for user by default #607

Closed yahor closed 5 months ago

yahor commented 6 months ago

606

codecov[bot] commented 6 months ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (c46f844) 57.64% compared to head (f8c3f22) 58.01%.

Files Patch % Lines
app/controllers/admin/users_controller.rb 0.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #607 +/- ## ========================================== + Coverage 57.64% 58.01% +0.36% ========================================== Files 65 66 +1 Lines 1412 1429 +17 ========================================== + Hits 814 829 +15 - Misses 598 600 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

abitrolly commented 6 months ago

Does Ruby have a constructor to initialize default values?

yahor commented 6 months ago

@abitrolly Ruby - yes. def initialize In Rails we use callback with condition after_initialize :set_default_tariff, if: :new_record?

abitrolly commented 6 months ago

I found this post https://itecnote.com/tecnote/rails-how-to-set-default-values-in-activerecord/ which uses universal init method for setting defaults, and it is called unconditionally.

Why it is not possible to specify defaults on a model level?