Active Record/Ruby on Rails -> Delete image by click on link: Set attachment columns to NULL via -


i not sure how this. have table called "animals". can add image display animal.

i use statement in form-view changing image:

f.file_field :attachment, :accept => 'image/jpeg' 

when submit form got nice looking image in show-view.

like said, can change image, not know how delete it. in perfect world prefer, press link , image gets deleted, rest of animals attributes stay alife, following columns set null , file gets deleted server:

"attachment_file_name" "attachment_content_type" "attachment_file_size" "attachment_update_at" (should set current date, or set null)

any apreciated.

if using paperclip gem need set attachment nil , save. this:

@animal.attachment = nil @animal.save 

more info here

in case, if want add link remove, create route , action this.

i suggest adding checkbox nearby file field , verify @ update/create.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -