Forcing browser redirects on a Ruby on Rails application

You could save the redirect requirement in a table in the database, with an appropriate relationship with the user, then use a before filter in the controller to check whether a redirect is required and do it.

Colin

Thanks for the reply Colin.

We do not know the user ids before hand. They will sign up for the research study, and the admin will decide which users to pair among the ones online. One user may be paired with three to four other users one after another. I want to have the admin control over the process so that we could pair a user with a third online user if one from the original pair got offline and did not return. So the decision about which url to redirect to must be made dynamically.

Do you think the Table approach would still work in the above scenario?

I was thinking of building some sort of a polling mechanism (i’m not super clear on how to do that as I am relatively new) where the browsers contact the server to confirm their online status. However I was confused as to how I could redirect two browsers to a common url.

I found this on stack-overflow: javascript - How to manage a redirect request after a jQuery Ajax call - Stack Overflow

Which seems to be a promising solution. What do you think?

Please don't top post it makes it difficult to follow the thread. Insert your reply at appropriate points in the previous message. Thanks

Thanks for the reply Colin.

We do not know the user ids before hand. They will sign up for the research study, and the admin will decide which users to pair among the ones online. One user may be paired with three to four other users one after another. I want to have the admin control over the process so that we could pair a user with a third online user if one from the original pair got offline and did not return. So the decision about which url to redirect to must be made dynamically.

Do you think the Table approach would still work in the above scenario?

I was thinking of building some sort of a polling mechanism (i'm not super clear on how to do that as I am relatively new) where the browsers contact the server to confirm their online status. However I was confused as to how I could redirect two browsers to a common url.

I found this on stack-overflow: javascript - How to manage a redirect request after a jQuery Ajax call - Stack Overflow Which seems to be a promising solution. What do you think?

Do you need the redirect to happen immediately the admin decides that it should happen? My solution (with a before_filter) will only redirect the next time the user requests a page. If you want it to happen immediately then yes, you will need to poll the server from the current page in the browser, using javascript.

Colin

Please don’t top post it makes it difficult to follow the thread.

Insert your reply at appropriate points in the previous message.

Thanks

Sure will keep that in mind.

Do you need the redirect to happen immediately the admin decides that

it should happen? My solution (with a before_filter) will only

redirect the next time the user requests a page. If you want it to

happen immediately then yes, you will need to poll the server from the

current page in the browser, using javascript.

Yes I need it to happen immediately the admin decides that it should happen. To implement the polling mechanism how can I enable the javascript to talk to the rails server?

..   Yes I need it to happen immediately the admin decides that it should happen. To implement the polling mechanism how can I enable the javascript to talk to the rails server?

That is a javascript issue rather than a rails one. Have a look at the javascript setTimeout function. However if you want to write sophisticated web apps you really need a good knowledge of javascript. I suggest working through some tutorials. Probably jQuery.

Colin