# Download video using link\_to

**URL:** <https://www.ruby-forum.com/t/download-video-using-link-to/144573>\
**Category:** Rails\
**Created:** [July 31, 2008, 3:41am UTC](https://www.ruby-forum.com/t/download-video-using-link-to/144573 "2008-07-31T03:41:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [July 31, 2008, 3:41am UTC](https://www.ruby-forum.com/t/download-video-using-link-to/144573/1 "2008-07-31T03:41:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [July 31, 2008, 3:53am UTC](https://www.ruby-forum.com/t/download-video-using-link-to/144573/2 "2008-07-31T03:53:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [July 31, 2008, 4:03am UTC](https://www.ruby-forum.com/t/download-video-using-link-to/144573/3 "2008-07-31T04:03:02Z")

</div>

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’ %\>

---

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [August 5, 2008, 2:44am UTC](https://www.ruby-forum.com/t/download-video-using-link-to/144573/4 "2008-08-05T02:44:03Z")

</div>

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
