Download video using link_to

Hello All,

I need to add a download video functionality to my website. Currently
my link looks like that :

<%=link_to “Download”, @video.public_filename %>

But I want to increment a column value (num_downloads) in my db eah
time this link is clicked. How can I achieve that.

Thanks

Joel

joel wrote:

Hello All,

I need to add a download video functionality to my website. Currently
my link looks like that :

<%=link_to “Download”, @video.public_filename %>

But I want to increment a column value (num_downloads) in my db eah
time this link is clicked. How can I achieve that.

Thanks

Joel

Link to an action, which updates the counter in the database, and use
send_file to respond to the request with the video.

joel wrote:

Hello All,

I need to add a download video functionality to my website. Currently
my link looks like that :

<%=link_to “Download”, @video.public_filename %>

But I want to increment a column value (num_downloads) in my db eah
time this link is clicked. How can I achieve that.

Thanks

Joel

maybe you can use this:

<%=link_to “Download”, @video.public_filename,:onclick=>‘some ajax code
to increment column value’ %>

Hello G.s,

so I tried this below :

<%=link_to “Download”,
@video.public_filename,
:onClick=>“downloadVideo(’#{download_video_url(@video.id)}’);alert(‘csdc’);”
%>

downloadVideo is a js function that goes like this below :

function downloadVideo(url) {
new Ajax.Request(url,{
method:‘get’
}

)};

But the problem is that I’m having a 500 Http error, so … my
routes.rb now regarding the videos goes like this :

map.resources :videos,
:member => {
:download => :get,
:create_comment => :post,
:paged_comments => :get
}

I can’t figure out why the download action cannot be invoked; if u
have any idea regarding this issue please let me know.

Regards,

Joel