Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic routes on runtime in Rails
    text
    copied!<p>I'm developing a site using refinery. Now for one specific page that is created in the back-end of refinery, i want to use my own controller and views. All the User can do with this page is to set the menu-position, title, meta-info etc. The URL for this page has to look the same as all the other pages.</p> <p>So for example, the menu structure looks like:</p> <ul> <li>menux</li> <li>menu1 <ul> <li>menu2 <ul> <li>specific page</li> </ul></li> </ul></li> <li>menux</li> </ul> <p>And the URL for "specific page" looks like "locale/menu1/menu2/specific page"</p> <p>The site is available in multiple languages, so i have to create these routes for all languages.</p> <p>Currently i'm creating the routes like this:</p> <pre><code>specific_page_id = 1 Refinery::I18n.frontend_locales.each do |lang| slugs = [] page = Refinery::Page.find_by_path_or_id(nil, specific_page_id) # get slug for page in current language slugs &lt;&lt; page.translations.select { |p| p.locale == lang }.first.slug # get all slugs from parrent pages while !page.parent_id.blank? page = Refinery::Page.find_by_path_or_id(nil, page.parent_id) slugs &lt;&lt; page.translations.select { |p| p.locale == lang }.first.slug end match "/:locale/#{slugs.reverse.join("/")}" =&gt; "controller#action", :via =&gt; :get, :constraints =&gt; { :locale =&gt; /#{lang}/ } end </code></pre> <p>With this, i'm getting a route to the specified page in every language like described above.</p> <p>But the problem is, when the user changes the name of the page or the position in the menu, the routes have to be generated again, which isn't done too often.</p> <p>Now my question is, how can i do this more dynamically on run-time? I've read a bit about constraints but i don't know if this is what i need.</p> <p>Thanks for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload