简体   繁体   中英

Ruby on Rails how to call javascript function from layout

I defined a javascript function called timeout() in the file app/views/download.js.erb . It polls a certain location in the server to see if a file is ready for download.

Now, I'm running it as a background process so the user should be able to navigate to different parts of the website while the polling function keeps on checking and checking until the file is ready for download and it will give a pop up message to the user.

So I want to run the timeout() function wherever the user is at so the checking is constantly running.

I'm thinking about calling this function in application.html.erb if session[:set_download] == 1 (which I set appropriately in the controller). My questions are

1) is application.html.erb the right place to call it?

2) timeout() is in app/views/download.js.erb ... so how do I call it in a file like application.html.erb (if it is the right place to place the call to timeout() )?

thanks!

1)您可以使用application.js放置代码2)添加// =要求下载,然后要求树

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM