Haven't been able to find anything specific to this issue (other searches deal with forms and such). It's probably a simple oversight on my part. But what on earth am I missing?
GOAL: I'm simply trying to redirect from the /login
page URL to the /dashboard
URL if a session exists.
EXPECTED OUTCOME: Calling redirect_to dashboard_index_url
or redirect_to '/dashboard'
should go to https://mydomain/dashboard
CURRENT OUTCOME: if I go to https://mydomain
after creating a session it redirects me to https://mydomaindashboard
, note the missing slash
ATTEMPTED SOLUTIONS:
- Manually type the URL https://mydomain/dashboard after creating a session, RESULT: works, so the proper route seems to exist
- Make manual route in
routes.rb
, RESULT: behavior is exactly the same asresource
routing with the missing slash - Clear browser cache, use different browswers RESULT: all exhibit same behavior
Here's what I have (abbreviated to relevant parts):
class LoginController < ApplicationController
def index
redirect_to dashboard_index_url if session[:user_id]
end
#...
end
class DashboardController < ApplicationController
before_action :require_login # calls redirect_to root_url unless session[:user_id]
def index
#...
end
end
# In routes.rb:
resources :login
resources :dashboard
# have also tried things like (removed the above line for these)
get 'dashboard' => "dashboard#index"
@Ryan Here is the current output for the routes:
$ rake routes
Prefix Verb URI Pattern Controller#Action
login_index GET /login(.:format) login#index
POST /login(.:format) login#create
new_login GET /login/new(.:format) login#new
edit_login GET /login/:id/edit(.:format) login#edit
login GET /login/:id(.:format) login#show
PATCH /login/:id(.:format) login#update
PUT /login/:id(.:format) login#update
DELETE /login/:id(.:format) login#destroy
dashboard GET /dashboard(.:format) dashboard#index
dashboard_index GET /dashboard(.:format) dashboard#index
POST /dashboard(.:format) dashboard#create
new_dashboard GET /dashboard/new(.:format) dashboard#new
edit_dashboard GET /dashboard/:id/edit(.:format) dashboard#edit
GET /dashboard/:id(.:format) dashboard#show
PATCH /dashboard/:id(.:format) dashboard#update
PUT /dashboard/:id(.:format) dashboard#update
DELETE /dashboard/:id(.:format) dashboard#destroy
root GET / login#index