Perhaps I''m not understanding this very well. I want to set a layout based on a domain name. The following works in ApplicationController.rb: before_filter :set_host case @host when ''site1.com'' layout ''site1'' when ''site2.com'' layout ''site2'' else layout ''default'' end def set_host @host = request.host end This returns an error for an undefined "request" method: case request.host when ''site1.com'' layout ''site1'' when ''site2.com'' layout ''site2'' else layout ''default'' end Why doesn''t the second one work? Thanks, Bill -- 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 -~----------~----~----~----~------~----~------~--~---
Because the actual controller doesn''t know about the request object until you call a method inside of it, like you''re doing with set_host. Put your case statement inside a method in any controller and it will work with request.host. On Dec 28, 2007 4:34 PM, Bill Devaul <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Perhaps I''m not understanding this very well. I want to set a layout > based on a domain name. > > The following works in ApplicationController.rb: > > before_filter :set_host > case @host > when ''site1.com'' > layout ''site1'' > when ''site2.com'' > layout ''site2'' > else > layout ''default'' > end > def set_host > @host = request.host > end > > This returns an error for an undefined "request" method: > > case request.host > when ''site1.com'' > layout ''site1'' > when ''site2.com'' > layout ''site2'' > else > layout ''default'' > end > > Why doesn''t the second one work? > > Thanks, > Bill > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> Because the actual controller doesn''t know about the request object > until > you call a method inside of it, like you''re doing with set_host. > Put your case statement inside a method in any controller and it will > work > with request.host.Thanks. I understand what you''ve said but why is controller only aware of the request object inside a method? Bill -- 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 addition, this doesn''t work: before_filter :determine_layout def determine_layout case request.host when ''site1.com'' layout ''site1'' when ''site2.com'' layout ''site2'' else layout ''application'' end end It reports there is an undefined method ''layout''. Why does the layout method disappear in the method? -- 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 -~----------~----~----~----~------~----~------~--~---
Bill Devaul wrote:> In addition, this doesn''t work: > > before_filter :determine_layout > def determine_layout > case request.host > when ''site1.com'' > layout ''site1'' > when ''site2.com'' > layout ''site2'' > else > layout ''application'' > end > end > > It reports there is an undefined method ''layout''. Why does the layout > method disappear in the method?It turns out none of this is working. Anyone know why the request object is not available in ApplicationController in Rails 2.01? Now, off to check 2.02.... -- 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 -~----------~----~----~----~------~----~------~--~---
This works: layout :determine_layout def determine_layout case request.host when ''site1.com'' : ''site1'' when ''site2.com'' : ''site2'' else ''application'' end end Now I can make a multi-domain site. Bill -- 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 -~----------~----~----~----~------~----~------~--~---