regex - Colons as divider with Rails Route? -


I would like to use colon in the root URL of my rail instead of my slash. Is it possible?


I am doing something like the following:

  match '* page_path / title: ": * section_path": ": section_title' = & gt; URL: 

Page_path = "Food / Fruit": title = "apple": section_path = "cooking: pie": SECTION_TITLE = "apple_pie"


This is possible in rail

Here's an approach:

  match 'food / fruit /: id' = & Gt; Add barriers to 'Page # Show' # IDs if you need Class Recycling & lt; ActiveRecord :: Base Def self.from_param (Ultimate) Title, section_path, SECTION_TITLE = extract_from_param (absolute) # Your search here logic, ex: find_by_title_and_section_path_and_section_title ... end def to_param # Your ultimate string here, # Prefix creation: "# {title} }: # {Section_path}: # {section_title} "# Be careful! Now this method will use this method instead of all your URLs #ID. # To be generated should be the ultimate, absolutely. Finally remove the personal def # exclamation token from self.extract_from_param parameter (from the other end)   

Then in your controller:

  @recipe = Recipe. From_param (Paramos [: id])   

Note that the option to use the built-in method is optionnal

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -