diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-08-17 22:57:21 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-08-17 22:57:21 -0300 |
commit | 76883f92374c6395f13c16628e1d87d40b6d2399 (patch) | |
tree | acb43a57d3601fdd9502599843eab27e8be095ff /activerecord/lib/rails/generators | |
parent | cdc00aba62ffb0f0af452f5152aafeb5e490962e (diff) | |
parent | fdfc0fc6c91b46a3ff769687e1a456ef2b205417 (diff) | |
download | rails-76883f92374c6395f13c16628e1d87d40b6d2399.tar.gz rails-76883f92374c6395f13c16628e1d87d40b6d2399.tar.bz2 rails-76883f92374c6395f13c16628e1d87d40b6d2399.zip |
Merge pull request #16062 from sgrif/sg-required-generators
Add a `required` option to the model generator
Diffstat (limited to 'activerecord/lib/rails/generators')
-rw-r--r-- | activerecord/lib/rails/generators/active_record/migration/migration_generator.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/rails/generators/active_record/model/templates/model.rb | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb index d3c853cfea..7a3c6f5e95 100644 --- a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb +++ b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb @@ -55,7 +55,7 @@ module ActiveRecord def attributes_with_index attributes.select { |a| !a.reference? && a.has_index? } end - + def validate_file_name! unless file_name =~ /^[_a-z0-9]+$/ raise IllegalMigrationNameError.new(file_name) diff --git a/activerecord/lib/rails/generators/active_record/model/templates/model.rb b/activerecord/lib/rails/generators/active_record/model/templates/model.rb index 808598699b..539d969fce 100644 --- a/activerecord/lib/rails/generators/active_record/model/templates/model.rb +++ b/activerecord/lib/rails/generators/active_record/model/templates/model.rb @@ -1,7 +1,7 @@ <% module_namespacing do -%> class <%= class_name %> < <%= parent_class_name.classify %> <% attributes.select(&:reference?).each do |attribute| -%> - belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %> + belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %> <% end -%> <% if attributes.any?(&:password_digest?) -%> has_secure_password |