From ecdcf06cb2e19e4bd2d883fbf3908cf196cfc1a5 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Sat, 30 Mar 2019 11:54:47 -0500 Subject: Add attachment and attachments field generators --- .../lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt | 3 +++ .../lib/rails/generators/erb/scaffold/templates/show.html.erb.tt | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'railties/lib/rails/generators/erb/scaffold/templates') diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt index b80c1280ce..1dddc3d698 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt @@ -21,6 +21,9 @@
<%%= form.label :password_confirmation %> <%%= form.password_field :password_confirmation %> +<% elsif attribute.attachments? -%> + <%%= form.label :<%= attribute.column_name %> %> + <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %> <% else -%> <%%= form.label :<%= attribute.column_name %> %> <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %> diff --git a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt index 7deba07926..6b216001d2 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +++ b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt @@ -3,7 +3,15 @@ <% attributes.reject(&:password_digest?).each do |attribute| -%>

<%= attribute.human_name %>: +<% if attribute.attachment? -%> + <%%= link_to @<%= singular_table_name %>.<%= attribute.column_name %>.filename, @<%= singular_table_name %>.<%= attribute.column_name %> %> +<% elsif attribute.attachments? -%> + <%% @<%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %> +

<%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %>
+ <%% end %> +<% else -%> <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> +<% end -%>

<% end -%> -- cgit v1.2.3