Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirect root url to somewhere else in Rails application
    primarykey
    data
    text
    <p>I have routes like this:</p> <pre><code>map.namespace 'prepayments', :path_prefix =&gt; '/:locale/prepayments' do |prepayment| prepayment.root :controller =&gt; 'login', :namespace =&gt; 'prepayments' ... end map.redirect '/', :controller =&gt; 'prepayments/login' # this is not working # I tried also map.root :controller =&gt; 'prepayments/login' </code></pre> <p>What I would like to get is that after typing: www.example.com it would redirect me to www.example.com/en/prepayments.</p> <p>Earlier when I used <code>map.root</code> from above example it just stayed at www.example.com and rendered correct view (but it was without <code>:locale</code> and it worked good), later I added <code>:locale</code> to my routes and from this time my view (that uses some form) doesn't work properly. I get error that it can't find corresponding route for form - which is right, because I didn't pass any <code>:locale</code>.</p> <p>So, how to redirect root to another page? It will probably need to generate correct path and pass it through http 302. Or/And how to make something like:</p> <pre><code>map.root :controller =&gt; 'prepayments/login', :my_locale =&gt; 'en' </code></pre> <p>EDIT: My rake routes looks like this:</p> <pre><code> prepayments_root /:locale/prepayments {:controller=&gt;"prepayments/login", :action=&gt;"index"} prepayments_create /:locale/prepayments/send_email {:method=&gt;:post, :controller=&gt;"prepayments/login", :action=&gt;"send_email"} prepayments_home /:locale/prepayments/home {:controller=&gt;"prepayments/prepayments", :action=&gt;"home"} prepayments_save /:locale/prepayments/save {:controller=&gt;"prepayments/prepayments", :action=&gt;"save"} prepayments_agree /:locale/prepayments/agree {:controller=&gt;"prepayments/prepayments", :action=&gt;"agree"} prepayments_disagree /:locale/prepayments/disagree {:controller=&gt;"prepayments/login", :action=&gt;"logout"} prepayments_payment /:locale/prepayments/payment {:controller=&gt;"prepayments/prepayments", :action=&gt;"payment"} prepayments_payment_email /:locale/prepayments/payment_email {:controller=&gt;"prepayments/prepayments", :action=&gt;"payment_email"} /:locale/prepayments/:uid {:controller=&gt;"prepayments/login", :action=&gt;"verify"} redirect / {:controller=&gt;"prepayments/login", :action=&gt;"index"} </code></pre> <p>EDIT:</p> <p>I tried doing it in the way Garrett proposed and it worked. I changed routes:</p> <pre><code>map.redirect '/', :controller =&gt; 'prepayments/login', :action =&gt; 'welcome' </code></pre> <p>and added welcome method in controller:</p> <pre><code>def welcome redirect_to prepayments_root_path(:locale =&gt; 'en') end </code></pre> <p>And it works as I wanted (so it changes url in my browser).</p> <p>The other way is to change routes like this:</p> <pre><code>map.root :controller =&gt; 'prepayments/login', :locale =&gt; 'en' </code></pre> <p>It also works, but it isn't redirecting (it doesn't change url in browser). I'm not sure if there is such option as <code>map.redirect</code>. I found it in examples on www but I also found plugin that add such functionality.</p> <p>Thanks for help!</p>
    singulars
    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.
 

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