Last active
March 14, 2017 08:58
-
-
Save rocLv/cd4d5da91fa1c99b82dc0ec7e1c1399f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/templates/active_record/model/model.rb | |
<% module_namespacing do -%> | |
class <%= class_name %> < <%= parent_class_name.classify %> | |
# keep the default scope first (if any) | |
# constants come up next | |
# afterwards we put attr related macros | |
# followed by association macros | |
<% attributes.select(&:reference?).each do |attribute| -%> | |
belongs_to :<%= attribute.name %><%= ' , polymophic: true' if attribute.polymophic? %><%= ' , required: true' if attribute.required? %> | |
<% end -%> | |
# and validation macros | |
# next we have callbacks | |
# other mactors (like devise's) should be placed after the callbacks | |
<% if attributes.any?(&:password_digest?) -%> | |
has_secure_password | |
<% end -%> | |
# finaly, scopes | |
end | |
<% end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rails model best practice