Here is part of my view, which can easily be put in a partial if necessary.
<% if order_item.still_downloadable == true %>
<%= "Photo ##{order_item.gallery_photo.id} - " %>
<%= link_to "Download here", download_order_order_item_path(@order, order_item) %>
• You may download this <%= pluralize(5 - order_item.download_count, 'more time') %>.
<% else %>
<%= "Photo ##{order_item.gallery_photo.id} - #{order_item.title}" %>
• You may not download this file any more.
<% end %>
Here is the download action in the order_items controller.
def download
@order_item = OrderItem.find(params[:id])
@gallery_photo = GalleryPhoto.find(@order_item.gallery_photo_id)
@order_item.update_attribute(:download_count, @order_item.download_count += 1)
send_file @gallery_photo.image.path(:original), :x_sendfile => true, :type => 'image/jpg'
end
What is the best way to refresh that part of the view (or even the whole page) so the download count is updated?
I made a download action and forced the show page to not cache, so when the users goes back to the show page the browser is forced to reload it. In the show action: