Hi
I am building a Rails application which aims at facilitating two users
to
collaborate on a web page based on their user id. The user matching
process
is a controlled one since the app is for research purposes. To support
the
same I am also building an admin interface which will allow the admin to
match two users so that both of them are redirected to a certain
webpage.
How can I force the user browsers to redirect to a common page, that I
selected?
Can it be done through Ajax or Javascript or ruby code? Any help or
pointers would be great.
Thanks
On 19 April 2013 07:00, karan verma [email protected] wrote:
Hi
I am building a Rails application which aims at facilitating two users to
collaborate on a web page based on their user id. The user matching process
is a controlled one since the app is for research purposes. To support the
same I am also building an admin interface which will allow the admin to
match two users so that both of them are redirected to a certain webpage.
How can I force the user browsers to redirect to a common page, that I
selected?
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
On 19 April 2013 09:43, karan verma [email protected] wrote:
Please don’t top post it makes it difficult to follow the thread.
Insert your reply at appropriate points in the previous message.
Thanks
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:
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
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:
Which seems to be a promising solution. What do you think?
On 19 April 2013 09:43, karan verma <[email protected] <javascript:>>
wrote:
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?
The table approach would still work: a subtask you need to solve is how
to allocate a unique URL to a bunch of user ids and then redirect them
to the new URL when the timeout expires.
I second Colin’s suggestion to use Javascript polling and the setTimeout
function, if it’s not critical for the users to wait for 10 seconds to
be redirected to the right URL.
If it’s very critical to redirect users quickly and waiting 10 secs is
too long, you can try 5 secs. You could also explore the approach of
implementing a push mechanism (I guess you can read discussions like
this one
to get you started). Choosing between the two is a tradeoff of 1) how
much time do you want to spend coding/researching the topic, 2) what are
the actual user requirements for your app, 3) how much load would the
server take.
Good luck,
Martin
On 19 April 2013 20:28, karan verma [email protected] wrote:
…
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
Thanks Martin and Colin.
With your help and reading some stack overflow posts i’ve arrived at a
solution that meets my need best. I’m posting it here so that it might
be
useful for other users.
Since I wanted the users to be redirected in real time to a URL chosen
by
the admin or an algorithm in real time. I needed a solution that could
push
updates from the server to browser. Also sometimes, accompanied by
events
from the browser that may be relayed to other browser.
The status quo presents three approaches:
-
Nodejs server + Redis + Socket.io- The following blog post has all
the
details and was incredibly useful.
Adding Real-Time To A RESTful Rails App - Liam Kaufman
-
Server Sent Events and Ajax: The following post by the creator of
Juggernaut explains how useful SSE could be and the reason why he killed
Juggernaut. Killing a library
-
Pusher: pusher.com
I started with the first option (Nodejs) after hearing a ton of good
things
about it. But finally realized that running Redis, Nodejs, Rails and
Socket.io would be an overkill. A complicated solution. I also read
about
hosting issues with Socket.io on heroku. Although I use Amazon Ec2, i
didn’t wanted to take a chance.
I decided against SSE because they are not supported Internet Explorer.
Moreover unlike websockets they are half duplex and thus might not be
the
best approach to implement presence, chat rooms or any other application
that requires full duplex communication.
I finally decided on using the third alternative. Pusher, although being
a
paid option has a sandbox plan that suits my current needs. Moreover, it
has great APIs for implementing realtime presence which greatly suits my
purpose. The documentation is very easy to follow as well.
I hope this helps someone in the future.
The table approach would still work: a subtask you need to solve is how
this one
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
–
Karan