Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing scope in routes to define a locale and trying to use a catch all
    primarykey
    data
    text
    <p>I'm using a scope to define a locale and also to allow my routes to be called without a locale, the problem I'm having is that with no locale specified, the routes think whatever the first path item is is now the locale. I'm wondering how I can limit this whilst still not requiring the locale for my named routes? I'm doing this to cater for a website overhaul and I want to catch old links and bring them to the old page nested inside the new layout.</p> <p>Here's what I'm doing:</p> <pre><code>scope "(:locale)", :locale =&gt; /en|es/ do match 'named_route\:id' end </code></pre> <p>I wonder is there a way to use a lamba to guarantee I have a two character locale and if not to bypass the scope? What I'm thinking is this might not be possible because my routes are accessible without the locale I'd have to check if it was a possible match for any routes below, which wouldn't be too hard.</p> <p>What I'm asking then is, is it possible to use a lamba to check the locale against an array of possibilities? i.e. "Locale is in [en,es,events,pages etc] then enter scope." This would mean if it has a locale, or if it possibly exists inside the named routes, it will enter the scope, otherwise it will avoid the scope and I can check against my 302 table before displaying a 404 if the page never existed.</p> <p>I hope this makes sense.</p> <p><strong>EDIT:</strong> Ok for now I've come up with a solution that works however it's not very elegant.</p> <p>As I have a before_filter in my application controller to set the locale to the default locale if it's not defined, I simply moved my root route to the end of the scope and inside my root method I check the locale is in one of the locals I cater for an if it, set the locale to my default locale and call my catch_all function.</p> <p>This works as if I goto mysite/no_route_for_this it sets my locale to be :no_route_for_this and calls my root route.</p> <p>A more elegant solution would be ideal here though.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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