0

I am trying to set the base address www.myplace.com/admin to be directed to www.myplace.com/admin/adminhub within the namespace coding below. I have tried every combination I can think of, but to no avail. I was trying to follow the same code used for the / of the app.

namespace :admin do
    ...
    get "adminhub"
    get 'admin', to: 'adminhub'

  end
11
  • base address? you mean root? Commented Jun 7, 2017 at 18:54
  • No, I am trying to set www.myplace.com/admin to resolve to www.myplace.com/admin/adminhub. Within the namespace. Commented Jun 7, 2017 at 18:57
  • You could put a redirect in admin/admin_controller#admin redirect_to "/admin/adminhub", status: 301. It isn't best practice, but it seems that train left the station long ago :) Commented Jun 7, 2017 at 18:59
  • You mean this get '/admin', to 'admin#adminhub'? Commented Jun 7, 2017 at 19:00
  • @Pavan when I put that in and restart my server it errors out giving me: 'rb:84: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' (SyntaxError) get '/sekret', to 'sekret#adminhub'' Commented Jun 7, 2017 at 19:05

1 Answer 1

1

Sounds like you want to redirect the browser to the new URL. You can do this with the redirect helper in the routes.

get '/admin', to: redirect('/admin/adminhub')

This allows you to redirect from one path to another. See the Redirection section in the Rails Routing Guide for more details.

Sign up to request clarification or add additional context in comments.

2 Comments

I got this to work with: get '', to: redirect('/admin/adminhub') from within the namespace code. Thank you for your help.
Ah, makes sense. You might also be able to more that outside the namespace block if you don't want the awkward get ''

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.