Remove redirects for root and put logic in routes

This commit is contained in:
benji 2015-01-09 12:31:14 +01:00
parent f595b0dba9
commit 7684f54120
7 changed files with 7 additions and 32 deletions

View file

@ -1,3 +0,0 @@
// Place all the styles related to the root controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -1,11 +0,0 @@
class RootController < ApplicationController
def root
if !current_user
redirect_to new_user_session_path
elsif current_user.koelkast?
redirect_to orders_path
else
redirect_to current_user
end
end
end

View file

@ -2,7 +2,7 @@ class UsersController < ApplicationController
load_and_authorize_resource only: [:destroy]
def show
@user = User.find(params[:id])
@user = User.find_by_id(params[:id]) || current_user
@orders = @user.orders.paginate(page: params[:page])
end

View file

@ -1,2 +0,0 @@
module RootHelper
end

View file

@ -2,11 +2,13 @@ Rails.application.routes.draw do
devise_for :users
devise_scope :user do
authenticated :user do
root to: 'root#root'
end
unauthenticated :user do
root to: 'devise/sessions#new', as: 'unauth_root'
root to: 'devise/sessions#new'
end
authenticated :user do
root to: 'devise/sessions#new', constraints: lambda { |req| req.env['warden'].user.nil? }, as: 'unauth_root'
root to: 'orders#overview', constraints: lambda { |req| req.env['warden'].user.koelkast? }, as: 'koelkast_root'
root to: 'users#show', constraints: lambda { |req| !req.env['warden'].user.koelkast? }, as: 'user_root'
end
end

View file

@ -1,7 +0,0 @@
require 'test_helper'
class RootControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -1,4 +0,0 @@
require 'test_helper'
class RootHelperTest < ActionView::TestCase
end