In a wiki, routes are handling web_index /:web {:controller=>"wiki", :action=>"index"} web_topic /:web/:topic {:controller=>"wiki", :action=>"view"} action /:web/:topic/:action {:controller=>"wiki"} That is the default action is "view". Two questions: 1. Can I constrain the patterns allowed for ":web" and ":topic" 2. Can I use that for something like webtopic /:web.:topic {:controller=>"wiki", :action=>"view"} Obviously part of the constraint is that neither part can contain a period. -- TCP/IP Illustrated... Is that the swimsuit edition? -- rgh22 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The answer to the first question is yes. You can do something like this: map.date "blog/:year/:month/:day", :controller => "blog", :action => "show_date", :requirements => { :year => /(19|20)\d\d/, :month => /[01]?\d/, :day => /[0-3]?\d/ }, :day => nil, :month => nil (Page 404 of Agile Web Development with Rails 2nd Ed) If :web and :topic are user created, you should probably also use active record validations validates_format_of ... The answer to question 2 is I think so since the standard routes include .:format On Dec 11, 7:10 pm, Anton J Aylward <a...-XdPx9462FWc@public.gmane.org> wrote:> In a wiki, routes are handling > > web_index /:web {:controller=>"wiki", :action=>"index"} > web_topic /:web/:topic {:controller=>"wiki", :action=>"view"} > action /:web/:topic/:action {:controller=>"wiki"} > > That is the default action is "view". > > Two questions: > > 1. Can I constrain the patterns allowed for ":web" and ":topic" > > 2. Can I use that for something like > > webtopic /:web.:topic {:controller=>"wiki", :action=>"view"} > > Obviously part of the constraint is that neither part can contain a period. > > -- > TCP/IP Illustrated... Is that the swimsuit edition? -- rgh22--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Is this something that varies with the version of Rials,because I''m having problems with it. I have in config/routes.rb: map.with_options(:controller => ''wiki'') do |wiki| wiki.web '':web'', :action => ''view'', :topic => ''HomePage'', :requirements => { :web => %r{[A-Z][a-z]+} } wiki.web_topic '':web/:topic'', :action => ''view'', :requirements => { :web => %r{[A-Z][a-z]+}, :topic => %r{([A-Z][a-z])+{2,}} } # Everything else wiki.connect ''*url'', :action => ''view_by_url'' end Before I added the ''requirements'' the following were caught correctly /System /System/CamelWord After I added the ''requirements'' everything ended up as ''view_by_url'' I''ve simplified the patterns all the way down, but I think they are right. I''ve tested at http://regexlib.com/ I''ve tried more "complicated" patterns: start of word/string markers, explicit quantifiers, groupings, greedy and ungreedy. No avail. I always end up with the ''view_by_url'' catch-all. I''m don''t see how ":format" is relevant. Could you expand on tat please. ptontiger said the following on 11/12/07 07:34 PM:> The answer to the first question is yes. > > You can do something like this: > > map.date "blog/:year/:month/:day", > :controller => "blog", > :action => "show_date", > :requirements => { :year => /(19|20)\d\d/, :month => /[01]?\d/, :day > => /[0-3]?\d/ }, > :day => nil, > :month => nil > > (Page 404 of Agile Web Development with Rails 2nd Ed) > > If :web and :topic are user created, you should probably also use > active record validations validates_format_of ... > > The answer to question 2 is I think so since the standard routes > include .:format > > On Dec 11, 7:10 pm, Anton J Aylward <a...-XdPx9462FWc@public.gmane.org> wrote: >> In a wiki, routes are handling >> >> web_index /:web {:controller=>"wiki", :action=>"index"} >> web_topic /:web/:topic {:controller=>"wiki", :action=>"view"} >> action /:web/:topic/:action {:controller=>"wiki"} >> >> That is the default action is "view". >> >> Two questions: >> >> 1. Can I constrain the patterns allowed for ":web" and ":topic" >> >> 2. Can I use that for something like >> >> webtopic /:web.:topic {:controller=>"wiki", :action=>"view"} >> >> Obviously part of the constraint is that neither part can contain a period. >>-- "It''s better to light a candle than to curse the darkness." - Eleanor Roosevelt --~--~---------~--~----~------------~-------~--~----~ 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 have part of that working. This part: wiki.web_topic '':web/:topic'', :action => ''view'', :web => nil, :topic => nil, :requirements => { :web => /[A-Z][a-z]+/, :topic => /([A-Z][a-z])+{2,}/, } I do need to make the regular expressions more comprehensive, though. But if extend it to: wiki.web_topic_action '':web/:topic/:action'', :requirements => { :web => /[A-Z][a-z]+/, :topic => /([A-Z][a-z])+{2,}/, :action => /[a-z][a-z_]{3,}/ } I don''t get matches. I also don''t get matches on a simpler, easier to test variation: wiki.web_action '':web/:action'', :requirements => { :web => /[A-Z][a-z]+/, :action => /[a-z][a-z_]{3,}/ } I take it that the "nil'' makes the field optional and if there is no ''nil'' then its mandatory. Is there a way to supply a default? If so, does it have to be a fixed string or can I pull it out of a configuration table in the database? ptontiger said the following on 11/12/07 07:34 PM:> The answer to the first question is yes. > > You can do something like this: > > map.date "blog/:year/:month/:day", > :controller => "blog", > :action => "show_date", > :requirements => { :year => /(19|20)\d\d/, :month => /[01]?\d/, :day > => /[0-3]?\d/ }, > :day => nil, > :month => nil > > (Page 404 of Agile Web Development with Rails 2nd Ed) > > If :web and :topic are user created, you should probably also use > active record validations validates_format_of ... > > The answer to question 2 is I think so since the standard routes > include .:format > > On Dec 11, 7:10 pm, Anton J Aylward <a...-XdPx9462FWc@public.gmane.org> wrote: >> In a wiki, routes are handling >> >> web_index /:web {:controller=>"wiki", :action=>"index"} >> web_topic /:web/:topic {:controller=>"wiki", :action=>"view"} >> action /:web/:topic/:action {:controller=>"wiki"} >> >> That is the default action is "view". >> >> Two questions: >> >> 1. Can I constrain the patterns allowed for ":web" and ":topic" >> >> 2. Can I use that for something like >> >> webtopic /:web.:topic {:controller=>"wiki", :action=>"view"} >> >> Obviously part of the constraint is that neither part can contain a period.-- When I used to teach creative writing, I would tell the students to make their characters want something right away even if it''s only a glass of water. Characters paralyzed by the meaninglessness of modern life still have to drink water from time to time. --Kurt Vonnegut --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Anton J Aylward said the following on 15/12/07 04:37 PM:> I have part of that working. > This part: > > wiki.web_topic '':web/:topic'', :action => ''view'', > :web => nil, > :topic => nil, > :requirements => { > :web => /[A-Z][a-z]+/, > :topic => /([A-Z][a-z])+{2,}/, > }WHOOP! Let me take that back. No it doesn''t work. ActionController::RoutingError (No route matches "/System/HomePage" with {:method=>:get}): -- Hell must be like a karaoke bar - sher-Pzr1fO3cD3pEgLnXhegG/Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---