Unless someone decides to upload two images or two CSS files.  This way the
last one wins.

On May 21, 2014, at 5:44 PM, Zach Rowe <notifications@github.com> wrote:

In app/controllers/templates_controller.rb:

>
> -    if @template.update_attributes(template_params)
> +    # get a copy of the params and remove the files as we process them
> +    tps = template_params
> +    tps[:media_attributes].each do |k, media|
> +      if !media.empty?
> +        # for the files that were uploaded, determine their media key based on their extension
> +        new_media = @template.media.build(media)
> +        extension = (new_media.file_name.blank? ? nil : new_media.file_name.split('.')[-1].downcase)
> +        new_media.key = (extension == "css" ? "css" : "original") unless extension.nil?
> +
> +        # mark any existing @template.media with this same key as replaced (obsolete)
> +        @template.media.each do |m|
> +          m.key = 'replaced_' + m.key if m.key == new_media.key and m != new_media #!m.new_record?
> +        end

Probably could be @template.media.each do { |m| m.key = "replaced_#{m.key}"
unless m.new_record? }

—
Reply to this email directly or view it on
GitHub<https://github.com/concerto/concerto/pull/925/files#r12932065>
.