Add controller action to define root based on user role
This commit is contained in:
parent
db23fd2181
commit
f595b0dba9
9 changed files with 31 additions and 2 deletions
3
app/assets/stylesheets/root.css.scss
Normal file
3
app/assets/stylesheets/root.css.scss
Normal file
|
@ -0,0 +1,3 @@
|
|||
// 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/
|
|
@ -27,7 +27,7 @@ class OrdersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def index
|
||||
def overview
|
||||
@users_by_name = User.members.order(:name)
|
||||
@users_by_order = User.members.order(:orders_count).reverse_order
|
||||
end
|
||||
|
|
11
app/controllers/root_controller.rb
Normal file
11
app/controllers/root_controller.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
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
|
2
app/helpers/root_helper.rb
Normal file
2
app/helpers/root_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module RootHelper
|
||||
end
|
|
@ -1,3 +1,4 @@
|
|||
<%= render partial: 'flash' %>
|
||||
<div class="row">
|
||||
<aside class="col-md-4">
|
||||
<section class="user_info">
|
||||
|
|
|
@ -3,7 +3,7 @@ Rails.application.routes.draw do
|
|||
|
||||
devise_scope :user do
|
||||
authenticated :user do
|
||||
root to: 'orders#index'
|
||||
root to: 'root#root'
|
||||
end
|
||||
unauthenticated :user do
|
||||
root to: 'devise/sessions#new', as: 'unauth_root'
|
||||
|
@ -18,4 +18,5 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :products
|
||||
get 'admins' => 'admins#schulden', as: "admins_schulden"
|
||||
get 'overview' => 'orders#overview', as: "orders"
|
||||
end
|
||||
|
|
7
test/controllers/root_controller_test.rb
Normal file
7
test/controllers/root_controller_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RootControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
4
test/helpers/root_helper_test.rb
Normal file
4
test/helpers/root_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RootHelperTest < ActionView::TestCase
|
||||
end
|
Loading…
Reference in a new issue