From 19a29c6556a53b7258bfbfb6164dff344649b331 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Thu, 28 Mar 2019 09:16:47 -0500 Subject: Add rich_text field to model generators --- .../lib/rails/generators/generated_attribute.rb | 27 ++++++++++++++-------- .../test_unit/model/templates/fixtures.yml.tt | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index a8f7729fd3..e801ab0c90 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -74,6 +74,7 @@ module Rails when :datetime, :timestamp then :datetime_select when :date then :date_select when :text then :text_area + when :rich_text then :rich_text_area when :boolean then :check_box else :text_field @@ -82,15 +83,15 @@ module Rails def default @default ||= case type - when :integer then 1 - when :float then 1.5 - when :decimal then "9.99" - when :datetime, :timestamp, :time then Time.now.to_s(:db) - when :date then Date.today.to_s(:db) - when :string then name == "type" ? "" : "MyString" - when :text then "MyText" - when :boolean then false - when :references, :belongs_to then nil + when :integer then 1 + when :float then 1.5 + when :decimal then "9.99" + when :datetime, :timestamp, :time then Time.now.to_s(:db) + when :date then Date.today.to_s(:db) + when :string then name == "type" ? "" : "MyString" + when :text then "MyText" + when :boolean then false + when :references, :belongs_to, :rich_text then nil else "" end @@ -152,6 +153,14 @@ module Rails type == :token end + def rich_text? + type == :rich_text + end + + def virtual? + rich_text? + end + def inject_options (+"").tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } } end diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt index ee4ae47727..0fd9f305d7 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt @@ -7,7 +7,7 @@ password_digest: <%%= BCrypt::Password.create('secret') %> <%- elsif attribute.reference? -%> <%= yaml_key_value(attribute.column_name.sub(/_id$/, ''), attribute.default || name) %> - <%- else -%> + <%- elsif !attribute.virtual? -%> <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- end -%> <%- if attribute.polymorphic? -%> -- cgit v1.2.3