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

java - unable show chart in xls document using jasper reports -

java.lang.RuntimeException: Could not generate dummy secret at sun.security.ssl.RSAClientKeyExchange.<init> -

javascript - How to change image src on success AJAX -