How update a field from from link?

Hi, I want delete the assigned image into a record. I modified the edit form to show the asigned image to a record and below the image I put a link "remove image" These link: <%= link_to "Delete Image", delete_image_path(@restaurant), :data => {:confirm => "Are you sure?"}, :method => :delete_image %> on routes I have: get 'restaurants/delete_image/:id' => 'restaurants#delete_image', via: :put on controller I have: def delete_image @restaurant=Restaurant.find(params[:id]); @restaurant.image=""; end But don't work. undefined method `delete_image_path' Can you help me? Salut, Josep M

Posted over 3 years ago by Josep M Yepes
Posted over 3 years ago by Alex Yang

It's great that you are starting to customize the Yelpdemo app already! However, I'd recommend finishing the course successfully before making your own customizations. This is because it will be hard to know how your changes may impact the rest of the course - by completing the course first, you will be starting with working knowledge of how everything ties together.

But to answer your question, there's some good info in the carrierwave documentation on how to do this. Namely, you should already have access to a 'remove_image' method (since our field was named 'image'), which you will be able to use in your controller action. Here's the link:
https://github.com/carrierwaveuploader/carrierwave#removing-uploaded-files

1
Posted over 3 years ago by Josep M Yepes

Hi Alex,
Seems that with carrierwave gem exist some kind of issue with the @user.remove_avatar.
Seems that delete the file but not update the image field. I'm testing it now... any experience or info about this issue?

1
Posted over 3 years ago by Alex Yang

I remember seeing an issue about this as well. If this still isn't resolved, it shouldn't be a big deal because you can just add another line or two in your controller to manually delete the image field.

1
Posted over 3 years ago by Josep M Yepes

Hi Alex,
The @restaurant.remove_image don't work, the @restaurant.remove_image! seems that work but the image appear and disappear so the field isn't updated properly.

So only left to use:
@restaurant.remove_image = true
@restaurant.save!

But... how I call that? Can you point me how call it?

1
Posted over 3 years ago by Alex Yang

There are (at least) 2 ways to call these. You can either call these directly from your controller-action, or you can define your own method in your model file and call on this method from your controller-action.

Make sure that in addition to observing whether the image appears on the page, you also check your database to see exactly what is being changed.

1
Posted over 3 years ago by Josep M Yepes

Hi Alex,
I don't know how do that from my model but from my controller I created "def deleteImage" but the routes don't work.
Can you show me a simple example to follow it?

1
Posted over 3 years ago by Alex Yang

If you haven't finished the course already, I'd recommend doing that first as you'll have a much better sense of how controllers, models, and views interact in Rails's MVC framework.

It sounds like you're also having some trouble with routing. Take a look at the RailsGuides article below - I find that this reading over this guide is a great intro to Rails routing:
http://guides.rubyonrails.org/routing.html

1
Posted over 3 years ago by Josep M Yepes

Thanks for answer Alex. I agree with you to finish before the Yelpdemo course.

About store the images, any way to store in my own server?

1
Posted over 3 years ago by Alex Yang

I'm not sure about storing in your own server, but carrierwave does allow you to use a variety of storage solutions (Amazon S3, etc). Check the documentation.

1