Hi. I am new to Rails. I am doing a web project for my school. It has models like Page, Student and Forum. Page model is for creating pages like home page, help, contact, about, feedback, etc. My route has my home page as :controller => "pages", :action => "show", :id => "1". Students have registrations to access and use the forum. I am using a cookie based session storage. How can i redirect the student to the forums index which is :controller => "forums", :action => "index" instead of home page even when he types the home page address(www.homepage.com), if he had already logged in and had set Remember my password. Thanks in advance. -- 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 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 -~----------~----~----~----~------~----~------~--~---
Sounds like you need a show-action-specific before_filter for your Pages controller: before_filter :redirect_to_forums, :only => [:show] def redirect_to_forums if logged_in? # you will need to define this redirect_to :controller => "forums" # index action is implied end end Anna Lissa On Fri, Jul 4, 2008 at 9:34 AM, Rock Roll <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi. I am new to Rails. I am doing a web project for my school. It has > models like Page, Student and Forum. Page model is for creating pages > like home page, help, contact, about, feedback, etc. My route has my > home page as :controller => "pages", :action => "show", :id => "1". > Students have registrations to access and use the forum. I am using a > cookie based session storage. How can i redirect the student to the > forums index which is :controller => "forums", :action => "index" > instead of home page even when he types the home page > address(www.homepage.com), if he had already logged in and had set > Remember my password. > > Thanks in advance. > -- > 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 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 -~----------~----~----~----~------~----~------~--~---
AnnaLissa Cruz wrote:> Sounds like you need a show-action-specific before_filter for your Pages > controller: > > before_filter :redirect_to_forums, :only => [:show] > > def redirect_to_forums > if logged_in? # you will need to define this > redirect_to :controller => "forums" # index action is implied > end > end > > Anna Lissa > > On Fri, Jul 4, 2008 at 9:34 AM, Rock Roll > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thank you for your reply. But i have a help page of route :controller=> "pages", :action => "show", :id => "2", a contact page with route :controller=> "pages", :action => "show", :id => "3" and so on. What will happen to the show action for those links if the user has logged in -- 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 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 see. It''s not very pretty but you can do this instead (with no before_filter): def show if params[:id] == 1 && logged_in? redirect_to :controller => "forums" return end # rest of your action definition end On Fri, Jul 4, 2008 at 11:35 AM, Rock Roll <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > AnnaLissa Cruz wrote: > > Sounds like you need a show-action-specific before_filter for your Pages > > controller: > > > > before_filter :redirect_to_forums, :only => [:show] > > > > def redirect_to_forums > > if logged_in? # you will need to define this > > redirect_to :controller => "forums" # index action is implied > > end > > end > > > > Anna Lissa > > > > On Fri, Jul 4, 2008 at 9:34 AM, Rock Roll > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Thank you for your reply. > But i have a help page of route :controller=> "pages", :action => > "show", :id => "2", a contact page with route :controller=> "pages", > :action => "show", :id => "3" and so on. What will happen to the show > action for those links if the user has logged in > -- > 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 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 -~----------~----~----~----~------~----~------~--~---
AnnaLissa Cruz wrote:> I see. It''s not very pretty but you can do this instead (with no > before_filter): > > def show > if params[:id] == 1 && logged_in? > redirect_to :controller => "forums" > return > end > # rest of your action definition > end > > On Fri, Jul 4, 2008 at 11:35 AM, Rock Roll > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Oh. I got it. Thanks Anna for your help. -- 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 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 -~----------~----~----~----~------~----~------~--~---
Rock Roll wrote:> AnnaLissa Cruz wrote: >> I see. It''s not very pretty but you can do this instead (with no >> before_filter): >> >> def show >> if params[:id] == 1 && logged_in? >> redirect_to :controller => "forums" >> return >> end >> # rest of your action definition >> end >> >> On Fri, Jul 4, 2008 at 11:35 AM, Rock Roll >> <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Oh. I got it. Thanks Anna for your help.I have another doubt. I have a navigation bar available to all controllers of the site with links Home, Help ,Contact,etc. So if i click Home, then won''t I be redirected to forums? -- 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 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 -~----------~----~----~----~------~----~------~--~---
In that case, you probably would be better off having your homepage route being map.root :controller => "pages" then in your PagesController: def index if params[:id] == 1 && logged_in?>> redirect_to :controller => "forums" >> return >> end@page = Page.find(1) render :action => :show end On Fri, Jul 4, 2008 at 9:28 PM, Rock Roll <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Rock Roll wrote: > > AnnaLissa Cruz wrote: > >> I see. It''s not very pretty but you can do this instead (with no > >> before_filter): > >> > >> def show > >> if params[:id] == 1 && logged_in? > >> redirect_to :controller => "forums" > >> return > >> end > >> # rest of your action definition > >> end > >> > >> On Fri, Jul 4, 2008 at 11:35 AM, Rock Roll > >> <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > > Oh. I got it. Thanks Anna for your help. > > I have another doubt. I have a navigation bar available to all > controllers of the site with links Home, Help ,Contact,etc. So if i > click Home, then won''t I be redirected to forums? > -- > 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 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 -~----------~----~----~----~------~----~------~--~---
oops, fat-fingered that. :) I meant: def index if logged_in? redirect_to :controller => "forums" return end @page = Page.find(1) render :action => :show end hope that helps a.l. On Fri, Jul 4, 2008 at 9:59 PM, AnnaLissa Cruz <annalissac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In that case, you probably would be better off having your homepage route > being > > map.root :controller => "pages" > > then in your PagesController: > > def index > if params[:id] == 1 && logged_in? > >> redirect_to :controller => "forums" > >> return > >> end > @page = Page.find(1) > render :action => :show > end > > > > > On Fri, Jul 4, 2008 at 9:28 PM, Rock Roll < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> Rock Roll wrote: >> > AnnaLissa Cruz wrote: >> >> I see. It''s not very pretty but you can do this instead (with no >> >> before_filter): >> >> >> >> def show >> >> if params[:id] == 1 && logged_in? >> >> redirect_to :controller => "forums" >> >> return >> >> end >> >> # rest of your action definition >> >> end >> >> >> >> On Fri, Jul 4, 2008 at 11:35 AM, Rock Roll >> >> <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> >> > >> > Oh. I got it. Thanks Anna for your help. >> >> I have another doubt. I have a navigation bar available to all >> controllers of the site with links Home, Help ,Contact,etc. So if i >> click Home, then won''t I be redirected to forums? >> -- >> 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 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 -~----------~----~----~----~------~----~------~--~---
AnnaLissa Cruz wrote:> oops, fat-fingered that. :) I meant: > > def index > if logged_in? > redirect_to :controller => "forums" > return > end > @page = Page.find(1) > render :action => :show > end > > > hope that helps > > a.l.Thank you -- 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 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 -~----------~----~----~----~------~----~------~--~---