Here is my need:
I have three prize, each prize has one pic, like:
prize1 pic1
prize2 pic2
prize3 pic3
Here is my design:
I use four record in my database, row 1 to 3 is mappingt to prize1 to prize3, and row4 is a default prize which can be used as adding prize.
Here comes the question:
When is user paperclip to upload my pic, there’s some problem to identify each pic. Details are following:
<form>
<input type="file" name="pic[]">
<input type="file" name="pic[]">
<input type="file" name="pic[]">
<input type="submit">
</form>
When I choose choose file to upload and submit the form, pic array will be passed by params, so I can get the the pic, and save them by the ordering of array.
However, when I only choose file for one prize, the array’s size will be 1, and I couldn’t judge which one has changed in the backend, so I’d like to hear from all of you, let me have a look at how you design it or could I make some changes to solve it!
You will want to make sure that the photo upload is the correct resource that is updating the prize that you are wanting.
Assuming that each prize in your database has its own row and paperclip column set up correctly you will want the form to be like this:
This should
PUTthe the picture information to the/prize/1234and the controller should consider the photo fields/params as attributes and update accordingly.Things to watch out for:
Good luck!