I have a situation where I need my ajaxed login popup to route to a different page than the default route. Specifically this situation is if they are trying to message a user and are not signed in, I want to show the login, and then route them to the profile that they were viewing and not make them have to find it again. The way I was thinking about doing it is to use a partial to add a hidden field that would contain the id of the user that is being viewed and use this id to render that profile instead of routing to the logged in users profile. The thing is that the partial is going to look the same as the regular which is not good DRY policy, but I dont know how else to get the user id for the hidden field into the login popup. Something like: page.replace_html "login", :partial => ''layouts/ login_for_diff_route'', :locals => {:profile_id => @profile_id} I cant really think of any other way to do it. Looking for any suggestions/advice/insights. Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I would store it in the session. session[:return_to] = url_for(profile_path(current_profile)) On Mar 16, 12:07 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a situation where I need my ajaxed login popup to route to a > different page than the default route. Specifically this situation is > if they are trying to message a user and are not signed in, I want to > show the login, and then route them to the profile that they were > viewing and not make them have to find it again. The way I was > thinking about doing it is to use a partial to add a hidden field that > would contain the id of the user that is being viewed and use this id > to render that profile instead of routing to the logged in users > profile. > > The thing is that the partial is going to look the same as the regular > which is not good DRY policy, but I dont know how else to get the user > id for the hidden field into the login popup. Something like: > > page.replace_html "login", :partial => ''layouts/ > login_for_diff_route'', :locals => {:profile_id => @profile_id} > > I cant really think of any other way to do it. Looking for any > suggestions/advice/insights. Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I think you are looking for something like this: By using the filters to check if the user is logged in or not and showing him the login partial. Now in the controller, if the user is successfully logged in try calling a method similar to the following: redirect_back_or_default(''/'') def redirect_back_or_default(default) session[:return_to] ? redirect_to_url(session[:return_to]) : redirect_to(default) session[:return_to] = nil end The above is extracted from the restful_authentication plugin. There the url is getting stored in the session[:return_to] where the user is redirected once authenticated. Please correct me if wrong. -- Thank You, Saideep Annadatha On Mon, Mar 16, 2009 at 4:37 AM, David <dlynam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a situation where I need my ajaxed login popup to route to a > different page than the default route. Specifically this situation is > if they are trying to message a user and are not signed in, I want to > show the login, and then route them to the profile that they were > viewing and not make them have to find it again. The way I was > thinking about doing it is to use a partial to add a hidden field that > would contain the id of the user that is being viewed and use this id > to render that profile instead of routing to the logged in users > profile. > > The thing is that the partial is going to look the same as the regular > which is not good DRY policy, but I dont know how else to get the user > id for the hidden field into the login popup. Something like: > > page.replace_html "login", :partial => ''layouts/ > login_for_diff_route'', :locals => {:profile_id => @profile_id} > > I cant really think of any other way to do it. Looking for any > suggestions/advice/insights. Thanks. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes, that is exactly what I was looking for. I am having some trouble calling this custom method within an ajax call though. I am able to call page.redirect_to user_path(user) but when I try the following: respond_to do |format| format.js do render :update do |page| page.redirect_back_or_default(user_path (logged_in_user)) #redirect_to user_path(logged_in_user) works end end end I get an error saying redirect_back_or_default is not defined. I have defined this within my LoginSystem module and have included this in the application file so it should be able to find it. Is there anything special I need to do to use it with RJS? On Mar 16, 11:04 pm, saideep annadatha <saideep.annada...-28guw/Z11fM@public.gmane.org> wrote:> Hi, > > I think you are looking for something like this: > > By using the filters to check if the user is logged in or not and showing > him the login partial. Now in the controller, if the user is successfully > logged in try calling a method similar to the following: > > redirect_back_or_default(''/'') > > def redirect_back_or_default(default) > session[:return_to] ? redirect_to_url(session[:return_to]) : > redirect_to(default) > session[:return_to] = nil > end > > The above is extracted from the restful_authentication plugin. > There the url is getting stored in the session[:return_to] where the user is > redirected once authenticated. > > Please correct me if wrong. > > -- > Thank You, > Saideep Annadatha > > On Mon, Mar 16, 2009 at 4:37 AM, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a situation where I need my ajaxed login popup to route to a > > different page than the default route. Specifically this situation is > > if they are trying to message a user and are not signed in, I want to > > show the login, and then route them to the profile that they were > > viewing and not make them have to find it again. The way I was > > thinking about doing it is to use a partial to add a hidden field that > > would contain the id of the user that is being viewed and use this id > > to render that profile instead of routing to the logged in users > > profile. > > > The thing is that the partial is going to look the same as the regular > > which is not good DRY policy, but I dont know how else to get the user > > id for the hidden field into the login popup. Something like: > > > page.replace_html "login", :partial => ''layouts/ > > login_for_diff_route'', :locals => {:profile_id => @profile_id} > > > I cant really think of any other way to do it. Looking for any > > suggestions/advice/insights. Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 18, 8:51 pm, Dave L <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, that is exactly what I was looking for. I am having some trouble > calling this custom method within an ajax call though. I am able to > call page.redirect_to user_path(user) but when I try the following: > > respond_to do |format| > format.js do > render :update do |page| > page.redirect_back_or_default(user_path > (logged_in_user)) #redirect_to user_path(logged_in_user) works > end > end > end > > I get an error saying redirect_back_or_default is not defined. I have > defined this within my LoginSystem module and have included this in > the application file so it should be able to find it. Is there > anything special I need to do to use it with RJS? >You''d have to define it on the javascript generator object that gets yielded to you. You''re better off doing if ... page.redirect_to ... else page.redirect_to ... end> On Mar 16, 11:04 pm, saideep annadatha <saideep.annada...-28guw/Z11fM@public.gmane.org> > wrote: > > > Hi, > > > I think you are looking for something like this: > > > By using the filters to check if the user is logged in or not and showing > > him the login partial. Now in the controller, if the user is successfully > > logged in try calling a method similar to the following: > > > redirect_back_or_default(''/'') > > > def redirect_back_or_default(default) > > session[:return_to] ? redirect_to_url(session[:return_to]) : > > redirect_to(default) > > session[:return_to] = nil > > end > > > The above is extracted from the restful_authentication plugin. > > There the url is getting stored in the session[:return_to] where the user is > > redirected once authenticated. > > > Please correct me if wrong. > > > -- > > Thank You, > > Saideep Annadatha > > > On Mon, Mar 16, 2009 at 4:37 AM, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a situation where I need my ajaxed login popup to route to a > > > different page than the default route. Specifically this situation is > > > if they are trying to message a user and are not signed in, I want to > > > show the login, and then route them to the profile that they were > > > viewing and not make them have to find it again. The way I was > > > thinking about doing it is to use a partial to add a hidden field that > > > would contain the id of the user that is being viewed and use this id > > > to render that profile instead of routing to the logged in users > > > profile. > > > > The thing is that the partial is going to look the same as the regular > > > which is not good DRY policy, but I dont know how else to get the user > > > id for the hidden field into the login popup. Something like: > > > > page.replace_html "login", :partial => ''layouts/ > > > login_for_diff_route'', :locals => {:profile_id => @profile_id} > > > > I cant really think of any other way to do it. Looking for any > > > suggestions/advice/insights. Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Okay, thats what I was going to do in the beginning, but the problem is how to define the variable for that if else statement. This is for a login, so for a certain page I was thinking about inserting a partial into the login popup form that would contain a hidden field of that id of the user that is being viewed. Then, in my authenticate action, I would check if there was a value in this field and if so, route to the users profiles whose id was in the hidden field and if there is no value, then just route to their profile. Does this work? Or is there a better way? I also thought about using sessions to store the user id of the user who is being viewed, but i would have to clear this session if the popup was closed and not submitted, and im just not sure how to do that. Thanks for your help. On Mar 18, 3:07 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 18, 8:51 pm, Dave L <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Yes, that is exactly what I was looking for. I am having some trouble > > calling this custom method within an ajax call though. I am able to > > call page.redirect_to user_path(user) but when I try the following: > > > respond_to do |format| > > format.js do > > render :update do |page| > > page.redirect_back_or_default(user_path > > (logged_in_user)) #redirect_to user_path(logged_in_user) works > > end > > end > > end > > > I get an error saying redirect_back_or_default is not defined. I have > > defined this within my LoginSystem module and have included this in > > the application file so it should be able to find it. Is there > > anything special I need to do to use it with RJS? > > You''d have to define it on the javascript generator object that gets > yielded to you. You''re better off doing > > if ... > page.redirect_to ... > else > page.redirect_to ... > end > > > On Mar 16, 11:04 pm, saideep annadatha <saideep.annada...-28guw/Z11fM@public.gmane.org> > > wrote: > > > > Hi, > > > > I think you are looking for something like this: > > > > By using the filters to check if the user is logged in or not and showing > > > him the login partial. Now in the controller, if the user is successfully > > > logged in try calling a method similar to the following: > > > > redirect_back_or_default(''/'') > > > > def redirect_back_or_default(default) > > > session[:return_to] ? redirect_to_url(session[:return_to]) : > > > redirect_to(default) > > > session[:return_to] = nil > > > end > > > > The above is extracted from the restful_authentication plugin. > > > There the url is getting stored in the session[:return_to] where the user is > > > redirected once authenticated. > > > > Please correct me if wrong. > > > > -- > > > Thank You, > > > Saideep Annadatha > > > > On Mon, Mar 16, 2009 at 4:37 AM, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have a situation where I need my ajaxed login popup to route to a > > > > different page than the default route. Specifically this situation is > > > > if they are trying to message a user and are not signed in, I want to > > > > show the login, and then route them to the profile that they were > > > > viewing and not make them have to find it again. The way I was > > > > thinking about doing it is to use a partial to add a hidden field that > > > > would contain the id of the user that is being viewed and use this id > > > > to render that profile instead of routing to the logged in users > > > > profile. > > > > > The thing is that the partial is going to look the same as the regular > > > > which is not good DRY policy, but I dont know how else to get the user > > > > id for the hidden field into the login popup. Something like: > > > > > page.replace_html "login", :partial => ''layouts/ > > > > login_for_diff_route'', :locals => {:profile_id => @profile_id} > > > > > I cant really think of any other way to do it. Looking for any > > > > suggestions/advice/insights. Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 18, 10:29 pm, Dave L <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Okay, thats what I was going to do in the beginning, but the problem > is how to define the variable for that if else statement. This is for > a login, so for a certain page I was thinking about inserting a > partial into the login popup form that would contain a hidden field of > that id of the user that is being viewed. Then, in my authenticate > action, I would check if there was a value in this field and if so, > route to the users profiles whose id was in the hidden field and if > there is no value, then just route to their profile. Does this work? > Or is there a better way? >Don''t see why it wouldn''t work. Fred> I also thought about using sessions to store the user id of the user > who is being viewed, but i would have to clear this session if the > popup was closed and not submitted, and im just not sure how to do > that. > > Thanks for your help. > > On Mar 18, 3:07 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 18, 8:51 pm, Dave L <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Yes, that is exactly what I was looking for. I am having some trouble > > > calling this custom method within an ajax call though. I am able to > > > call page.redirect_to user_path(user) but when I try the following: > > > > respond_to do |format| > > > format.js do > > > render :update do |page| > > > page.redirect_back_or_default(user_path > > > (logged_in_user)) #redirect_to user_path(logged_in_user) works > > > end > > > end > > > end > > > > I get an error saying redirect_back_or_default is not defined. I have > > > defined this within my LoginSystem module and have included this in > > > the application file so it should be able to find it. Is there > > > anything special I need to do to use it with RJS? > > > You''d have to define it on the javascript generator object that gets > > yielded to you. You''re better off doing > > > if ... > > page.redirect_to ... > > else > > page.redirect_to ... > > end > > > > On Mar 16, 11:04 pm, saideep annadatha <saideep.annada...-28guw/Z11fM@public.gmane.org> > > > wrote: > > > > > Hi, > > > > > I think you are looking for something like this: > > > > > By using the filters to check if the user is logged in or not and showing > > > > him the login partial. Now in the controller, if the user is successfully > > > > logged in try calling a method similar to the following: > > > > > redirect_back_or_default(''/'') > > > > > def redirect_back_or_default(default) > > > > session[:return_to] ? redirect_to_url(session[:return_to]) : > > > > redirect_to(default) > > > > session[:return_to] = nil > > > > end > > > > > The above is extracted from the restful_authentication plugin. > > > > There the url is getting stored in the session[:return_to] where the user is > > > > redirected once authenticated. > > > > > Please correct me if wrong. > > > > > -- > > > > Thank You, > > > > Saideep Annadatha > > > > > On Mon, Mar 16, 2009 at 4:37 AM, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I have a situation where I need my ajaxed login popup to route to a > > > > > different page than the default route. Specifically this situation is > > > > > if they are trying to message a user and are not signed in, I want to > > > > > show the login, and then route them to the profile that they were > > > > > viewing and not make them have to find it again. The way I was > > > > > thinking about doing it is to use a partial to add a hidden field that > > > > > would contain the id of the user that is being viewed and use this id > > > > > to render that profile instead of routing to the logged in users > > > > > profile. > > > > > > The thing is that the partial is going to look the same as the regular > > > > > which is not good DRY policy, but I dont know how else to get the user > > > > > id for the hidden field into the login popup. Something like: > > > > > > page.replace_html "login", :partial => ''layouts/ > > > > > login_for_diff_route'', :locals => {:profile_id => @profile_id} > > > > > > I cant really think of any other way to do it. Looking for any > > > > > suggestions/advice/insights. Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
When I try to add the form element in a partial: <%= f.hidden_field :profile_id, :value => profile_id %> I get an error that f is unknown. Is there a way to add form elements with a partial? On Mar 18, 4:10 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 18, 10:29 pm, Dave L <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Okay, thats what I was going to do in the beginning, but the problem > > is how to define the variable for that if else statement. This is for > > a login, so for a certain page I was thinking about inserting a > > partial into the login popup form that would contain a hidden field of > > that id of the user that is being viewed. Then, in my authenticate > > action, I would check if there was a value in this field and if so, > > route to the users profiles whose id was in the hidden field and if > > there is no value, then just route to their profile. Does this work? > > Or is there a better way? > > Don''t see why it wouldn''t work. > > Fred > > > I also thought about using sessions to store the user id of the user > > who is being viewed, but i would have to clear this session if the > > popup was closed and not submitted, and im just not sure how to do > > that. > > > Thanks for your help. > > > On Mar 18, 3:07 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Mar 18, 8:51 pm, Dave L <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Yes, that is exactly what I was looking for. I am having some trouble > > > > calling this custom method within an ajax call though. I am able to > > > > call page.redirect_to user_path(user) but when I try the following: > > > > > respond_to do |format| > > > > format.js do > > > > render :update do |page| > > > > page.redirect_back_or_default(user_path > > > > (logged_in_user)) #redirect_to user_path(logged_in_user) works > > > > end > > > > end > > > > end > > > > > I get an error saying redirect_back_or_default is not defined. I have > > > > defined this within my LoginSystem module and have included this in > > > > the application file so it should be able to find it. Is there > > > > anything special I need to do to use it with RJS? > > > > You''d have to define it on the javascript generator object that gets > > > yielded to you. You''re better off doing > > > > if ... > > > page.redirect_to ... > > > else > > > page.redirect_to ... > > > end > > > > > On Mar 16, 11:04 pm, saideep annadatha <saideep.annada...-J5qSqr+gpPw@public.gmane.orgz> > > > > wrote: > > > > > > Hi, > > > > > > I think you are looking for something like this: > > > > > > By using the filters to check if the user is logged in or not and showing > > > > > him the login partial. Now in the controller, if the user is successfully > > > > > logged in try calling a method similar to the following: > > > > > > redirect_back_or_default(''/'') > > > > > > def redirect_back_or_default(default) > > > > > session[:return_to] ? redirect_to_url(session[:return_to]) : > > > > > redirect_to(default) > > > > > session[:return_to] = nil > > > > > end > > > > > > The above is extracted from the restful_authentication plugin. > > > > > There the url is getting stored in the session[:return_to] where the user is > > > > > redirected once authenticated. > > > > > > Please correct me if wrong. > > > > > > -- > > > > > Thank You, > > > > > Saideep Annadatha > > > > > > On Mon, Mar 16, 2009 at 4:37 AM, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I have a situation where I need my ajaxed login popup to route to a > > > > > > different page than the default route. Specifically this situation is > > > > > > if they are trying to message a user and are not signed in, I want to > > > > > > show the login, and then route them to the profile that they were > > > > > > viewing and not make them have to find it again. The way I was > > > > > > thinking about doing it is to use a partial to add a hidden field that > > > > > > would contain the id of the user that is being viewed and use this id > > > > > > to render that profile instead of routing to the logged in users > > > > > > profile. > > > > > > > The thing is that the partial is going to look the same as the regular > > > > > > which is not good DRY policy, but I dont know how else to get the user > > > > > > id for the hidden field into the login popup. Something like: > > > > > > > page.replace_html "login", :partial => ''layouts/ > > > > > > login_for_diff_route'', :locals => {:profile_id => @profile_id} > > > > > > > I cant really think of any other way to do it. Looking for any > > > > > > suggestions/advice/insights. Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---