karan verma
2013-Apr-19 06:00 UTC
Forcing browser redirects on a Ruby on Rails application
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/8_J72sDvu1gJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Apr-19 07:45 UTC
Re: Forcing browser redirects on a Ruby on Rails application
On 19 April 2013 07:00, karan verma <karan.verma86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
karan verma
2013-Apr-19 08:43 UTC
Re: Forcing browser redirects on a Ruby on Rails application
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: http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call/1534662#1534662 Which seems to be a promising solution. What do you think? On Friday, 19 April 2013 00:45:18 UTC-7, Colin Law wrote:> > On 19 April 2013 07:00, karan verma <karan....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> > 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 >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/cV6UtN3o2oUJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Apr-19 10:53 UTC
Re: Forcing browser redirects on a Ruby on Rails application
On 19 April 2013 09:43, karan verma <karan.verma86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> 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: > http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call/1534662#1534662 > 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> > On Friday, 19 April 2013 00:45:18 UTC-7, Colin Law wrote: >> >> On 19 April 2013 07:00, karan verma <karan....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
karan verma
2013-Apr-19 19:28 UTC
Re: Forcing browser redirects on a Ruby on Rails application
On 19 April 2013 09:43, karan verma <karan....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <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 shouldhappen. To implement the polling mechanism how can I enable the javascript to talk to the rails server?> > > > > On Friday, 19 April 2013 00:45:18 UTC-7, Colin Law wrote: > >> > >> On 19 April 2013 07:00, karan verma <karan....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zeK16vChEXQJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Apr-19 20:04 UTC
Re: Forcing browser redirects on a Ruby on Rails application
On 19 April 2013 20:28, karan verma <karan.verma86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> > >> >> >> > >> > On Friday, 19 April 2013 00:45:18 UTC-7, Colin Law wrote: >> >> >> >> On 19 April 2013 07:00, karan verma <karan....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Martin Gogov
2013-Apr-21 14:49 UTC
Re: Forcing browser redirects on a Ruby on Rails application
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 http://stackoverflow.com/questions/219868/client-notification-should-i-use-an-ajax-push-or-poll 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
karan verma
2013-Apr-22 05:42 UTC
Re: Re: Forcing browser redirects on a Ruby on Rails application
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: 1. Nodejs server + Redis + Socket.io- The following blog post has all the details and was incredibly useful. http://liamkaufman.com/blog/2013/02/27/adding-real-time-to-a-restful-rails-app/ 2. 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. http://blog.alexmaccaw.com/killing-a-library 3. 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> 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 > > http://stackoverflow.com/questions/219868/client-notification-should-i-use-an-ajax-push-or-poll > 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 > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/rubyonrails-talk/dKT1uvyfWhA/unsubscribe?hl=en-US > . > To unsubscribe from this group and all its topics, send an email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- Karan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.