I am trying to implement a mobile interface using the access url, / mobile/ vs. / to deliver the alternate views by setting the template_root. I thought I could place a route such as, "map.connect ''/:segment1/:controller/:action/:id'', :requirement => {:segment1 => / mob/} before the default route and it should only match a url with mobile at the beginning. I am having nothing but trouble getting the routes to work. Any advice would be greatly appreciated. -- Lon Baker Speedymac LLC http://www.speedymac.com AIM: spdemac Skype: spdemac
Hi Lon, At the moment routes will only accept the URL if it matches the entire component. If you instead do :segment => /^mob.*$/ it will work... Personally I''m not a big fan of this behavior, but I haven''t heard too many complaints so it hasn''t been changed.
Nicholas, Thanks for the suggestion. Actually I am not using a component name, but a portion of the URL to set a different template_root. In the Application Controller I have the following code called as the first filter:> if @request.env[''PATH_INFO''].match(/\/mobile\//) > ::ActionController::Base.template_root = "#{RAILS_ROOT}/app/ > mobile/" > else > ::ActionController::Base.template_root = "#{RAILS_ROOT}/app/ > views/" > endIn the routes.rb I have the following routes placed prior to the defaults:> map.connect ''/:segment1/'', :controller => ''start'', :requirement => > {:segment1 => /mobile/} > map.connect ''/:segment1/:controller/:action/:id'', :requirement => > {:segment1 => /mobile/}It _seems_ to be working relatively well. Occasionally on logout the incorrect login page is returned. My suspicion is that I am not setting the template_root soon enough in that case. In my previous life, as a WebObjects developer, I used a technique of mapping the mobile views to the standard views. This allowed one set of models and controllers to interact with both web and mobile versions of viewers. It worked really well and that is what I am attempting to achieve here. On Jun 1, 2005, at 3:44 PM, rails-request-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org wrote:> At the moment routes will only accept the URL if it matches the entire > component. If you instead do :segment => /^mob.*$/ it will work... > > Personally I''m not a big fan of this behavior, but I haven''t heard too > many complaints so it hasn''t been changed.-- Lon Baker Speedymac LLC http://www.speedymac.com AIM: spdemac Skype: spdemac
Lon Baker wrote:> Nicholas, > > Thanks for the suggestion. Actually I am not using a component name, > but a portion of the URL to set a different template_root.Sorry for the confusion. By component I mean the segment of the URL between two / characters.> > In the Application Controller I have the following code called as the > first filter: > >> if @request.env[''PATH_INFO''].match(/\/mobile\//) >> ::ActionController::Base.template_root = "#{RAILS_ROOT}/app/ >> mobile/" >> else >> ::ActionController::Base.template_root = "#{RAILS_ROOT}/app/ >> views/" >> end > > > In the routes.rb I have the following routes placed prior to the > defaults: > >> map.connect ''/:segment1/'', :controller => ''start'', :requirement => >> {:segment1 => /mobile/} >> map.connect ''/:segment1/:controller/:action/:id'', :requirement => >> {:segment1 => /mobile/} >If the only thing :segment1 will be matching ''mobile'', then you can use map.connect ''mobile/:controller/:action/:id'', :media_type => ''mobile'' map.connect '':controller/:action/:id'', :media_type => ''screen'' Then your before filter could be # Set the correct template root for this request. before_filter do |controller| prefix = case controller.params[:media_type] when ''mobile'' then "app/mobile" else "app/views" end ::ActionController::Base.template_root = "#{RAILS_ROOT}/#{prefix}" end Anyhow, if what you have now isn''t broken, why fix it? :-) Cheers, Nicholas IMPOSSIBLE, adj: (1) I wouldn''t like it and when it happens I won''t approve; (2) I can''t be bothered; (3) God can''t be bothered. - The Hipcrime Vocab by Chad C. Mulligan