ruby on rails - How to delete attachment using refile ActiveRecord::RecordNotFound -


i'm trying delete / destroy attachment have uploaded using refile gem, , i'm getting following error, activerecord::recordnotfound in imagescontroller#destroy

couldn't find image 'id'=

images_controller.rb

def destroy         # binding.pry         @image = image.find(params[:id])         @image.destroy         flash[:notice] = 'deleted'         render 'new'     end      private      def image_params         params.require(:image).permit(:tshirt_image, :remove_tshirt_image)     end 

and form / view in i'm trying delete attachment looks like,

show.html.erb

<h1>show.html.erb</h1>  <% debug(@image) %>  <%= image_tag attachment_url(@image, :tshirt_image, :fill, 300, 300, format: "jpg") %>  <%= form_for @image |form| %>   <%= form.label :tshirt_image %>   <% form.attachment_field :tshirt_image %>    <%= form.check_box :remove_tshirt_image %>   <%= form.label :remove_tshirt_image %>    <%= button_to "delete", @image, method: :delete %>   <% end %>  <p>test</p> 

if i'm reading code correctly, of form's params nested under :image key (params[:image][:remove_tshirt_image], etc).

try:

@image = image.find(params[:image][:id])


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -