ruby on rails - Remove paperclip images Active Admin -
I want to be able to delete images within my editing form using formtastic in Active_admin. There are many posts about this but I do not seem to fit it with my setup for some reason.
I have a post
model and a news images
model that holds pictures for each post:
Class posts & lt; ActiveRecord :: Base is: Medium: News_imes, Dependent :: Approves to delete: _state_data_manufacturer: Newsmize, permission_decurity: true end class newsmase & lt; ActiveRecord :: Base is_to: post has_attached_file: photo end
So whatever I have read in my flag, it can be added to our news image model, and before saving that method, Will remove the image. I envision it to look like this, but clicking on the checkbox is wont to delete the image.
# / admin / post.rb f.has_many: news_images do | P | If p.object.new_record? P.input: Photo, as: file another p.input: photo, as :: file ,: hint = & gt; P.template.image_tag (p.object.photo.url (thumbs)) p.input: remove_image, as :: bullion, required :: wrong, label: remove image 'end'
What I have seen inside the console at this level is that when the check box is clicked and its value is not checked or unchecked ... is it considered?
News image model is now watching such as
class newsmazel & lt; ActiveRecord :: Base before_save: remove_photo related_to: personal def remove_photo self.photo.destroy if self.remove_image == '1' end end
is there anything here that anyone can see Is it because of not working or is there a solution for such an establishment?
Any help appreciated
Hope this is in the same condition Anyone will help. You do not need to create a custom method to delete images, you can easily use it in your form
p.input: _destroy, as :: booolan, required :: incorrect, Label: 'Remove image'
and pass your controller (permit_params)
: _ destruction
your nested Within features, e.g.
permit_params: title ,: content ,: news_category_id ,: author, news_images_attributes: [: id,: photo, post_id, _destroy]
Comments
Post a Comment