Using Rails 4.0.2 and paperclip 3.5.3
I want to be able to clone the same model (Event) for any given dates that the user puts in the form. So if I want to have events day x, x+1 and x+2, I'll need to copy the paperclip attachment (which happens to be an image) over to the x+1 and x+2 events.
In theory, it should be enough to do something along the lines of
def create
respond_to do |format|
if @event.save
dates.each do |date| #the date var comes from another place, redacted for clearness
event = @event.dup
event.photo = @eevnt.photo
event.save
end
end
end
But it doesn't.
It somehow marks the paperclip attachments for deletion.
Here's a copy of the log:
Processing by EventsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"U9H0RPuSKd1NgjMsoqHCAUqNW+IrWtZZM9PtzGAefTA=", "event"=>{"title"=>"fecha", "event_type"=>"conciertos", "province"=>"Madrid", "city"=>"Madrid", "replication_dates"=>"30/01/2014,31/01/2014", "time_template_hour"=>"12", "time_template_minute"=>"0", "location_name"=>"Sala Lapusuvi", "address"=>"Cl. albasanz 72", "description"=>"
lorem
\r\n", "photo"=>#, @original_filename="_MG_4256.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"event[photo]\"; filename=\"_MG_4256.jpg\"\r\nContent-Type: image/jpeg\r\n">, "youtube_video"=>"", "event_tickets_attributes"=>{"1390997939186"=>{"name"=>"General", "price"=>"10", "stock"=>"10", "_destroy"=>"false"}}, "fee_handler"=>"0", "no_print_event"=>"0", "terms"=>"1", "status"=>""}, "commit"=>"Crear mi evento"} Promoter Load (0.9ms) SELECT "promoters".* FROM "promoters" WHERE "promoters"."id" = 2 ORDER BY "promoters"."id" ASC LIMIT 1 Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: convert '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' -auto-orient -resize "250" '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg20140129-1873-1ng5mxd' Command :: file -b --mime '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg20140129-1873-1ng5mxd' Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: convert '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' -auto-orient -resize "x300" -crop "300x300+75+0" +repage '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg20140129-1873-1elyw4x' Command :: file -b --mime '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg20140129-1873-1elyw4x' Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' Command :: convert '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg.jpg[0]' -auto-orient -resize "x100" -crop "100x100+25+0" +repage '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg20140129-1873-1uzuzbr' Command :: file -b --mime '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-ye9lkg20140129-1873-1uzuzbr' (0.2ms) begin transaction DBG: TERMS => "1" Event Exists (0.3ms) SELECT 1 AS one FROM "events" WHERE ("events"."title" = 'fecha' AND "events"."timeline" = '2014-01-30 11:00:00.000000') LIMIT 1 Binary data inserted forstring
type on columnphoto_content_type
SQL (1.2ms) INSERT INTO "events" ("address", "city", "created_at", "description", "event_type", "fee_handler", "location_name", "photo_content_type", "photo_file_name", "photo_file_size", "photo_updated_at", "promoter_id", "province", "timeline", "title", "updated_at", "youtube_video") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["address", "Cl. albasanz 72"], ["city", "Madrid"], ["created_at", Wed, 29 Jan 2014 13:37:17 CET +01:00], ["description", "lorem
\r\n"], ["event_type", "conciertos"], ["fee_handler", 0], ["location_name", "Sala Lapusuvi"], ["photo_content_type", "image/jpeg"], ["photo_file_name", "_MG_4256.jpg"], ["photo_file_size", 360091], ["photo_updated_at", Wed, 29 Jan 2014 13:37:16 CET +01:00], ["promoter_id", 2], ["province", "Madrid"], ["timeline", Thu, 30 Jan 2014 12:00:00 CET +01:00], ["title", "fecha"], ["updated_at", Wed, 29 Jan 2014 13:37:17 CET +01:00], ["youtube_video", ""]] SQL (0.6ms) INSERT INTO "event_tickets" ("created_at", "event_id", "name", "price", "stock", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Wed, 29 Jan 2014 13:37:17 CET +01:00], ["event_id", 98], ["name", "General"], ["price", 10.0], ["stock", 10], ["updated_at", Wed, 29 Jan 2014 13:37:17 CET +01:00]] (24.6ms) commit transaction EventTicket Load (0.4ms) SELECT "event_tickets".* FROM "event_tickets" WHERE "event_tickets"."event_id" = ? [["event_id", 98]] Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: convert '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' -auto-orient -resize "250" '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y820140129-1873-1jxdah6' Command :: file -b --mime '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y820140129-1873-1jxdah6' Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: convert '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' -auto-orient -resize "x300" -crop "300x300+75+0" +repage '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y820140129-1873-1uq5p2o' Command :: file -b --mime '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y820140129-1873-1uq5p2o' Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: identify -format %m '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' Command :: convert '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y8.jpg[0]' -auto-orient -resize "x100" -crop "100x100+25+0" +repage '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y820140129-1873-q03px0' Command :: file -b --mime '/var/folders/q1/txykj42x56g0v_4pfn_3fs0r0000gn/T/_MG_425620140129-1873-azu3y820140129-1873-q03px0' (0.2ms) begin transaction DBG: TERMS => "1" Event Exists (0.3ms) SELECT 1 AS one FROM "events" WHERE ("events"."title" = 'fecha' AND "events"."timeline" = '2014-01-31 11:00:00.000000') LIMIT 1 Binary data inserted forstring
type on columnphoto_content_type
SQL (1.4ms) INSERT INTO "events" ("address", "city", "created_at", "description", "event_type", "fee_handler", "location_name", "photo_content_type", "photo_file_name", "photo_file_size", "photo_updated_at", "promoter_id", "province", "timeline", "title", "updated_at", "youtube_video") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["address", "Cl. albasanz 72"], ["city", "Madrid"], ["created_at", Wed, 29 Jan 2014 13:37:18 CET +01:00], ["description", "lorem
\r\n"], ["event_type", "conciertos"], ["fee_handler", 0], ["location_name", "Sala Lapusuvi"], ["photo_content_type", "image/jpeg"], ["photo_file_name", "_MG_4256.jpg"], ["photo_file_size", 360091], ["photo_updated_at", Wed, 29 Jan 2014 13:37:16 CET +01:00], ["promoter_id", 2], ["province", "Madrid"], ["timeline", Fri, 31 Jan 2014 12:00:00 CET +01:00], ["title", "fecha"], ["updated_at", Wed, 29 Jan 2014 13:37:18 CET +01:00], ["youtube_video", ""]] SQL (0.4ms) INSERT INTO "event_tickets" ("created_at", "event_id", "name", "price", "stock", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Wed, 29 Jan 2014 13:37:18 CET +01:00], ["event_id", 99], ["name", "General"], ["price", 10.0], ["stock", 10], ["updated_at", Wed, 29 Jan 2014 13:37:18 CET +01:00]] [paperclip] deleting /Users/fxjade/Documents/company/app/public/system/events/photos/000/000/098/original/_MG_4256.jpg [paperclip] deleting /Users/fxjade/Documents/company/app/public/system/events/photos/000/000/098/buy/_MG_4256.jpg [paperclip] deleting /Users/fxjade/Documents/company/app/public/system/events/photos/000/000/098/medium/_MG_4256.jpg [paperclip] deleting /Users/fxjade/Documents/company/app/public/system/events/photos/000/000/098/thumb/_MG_4256.jpg (18.1ms) commit transaction Rendered promoter_mailer/event_created_email.html.erb (0.9ms)
Has this happened to anyone before?
Any input on why doing it from the console works but I can't pull the-same-stunt from a controller?