From d656f333895c8ddf4585976d35cfae7aa01023f8 Mon Sep 17 00:00:00 2001 From: mohanbabu Date: Sun, 16 Jul 2017 10:06:05 +0800 Subject: [PATCH] working wih a and a --- app/assets/javascripts/home.coffee | 3 +++ app/assets/stylesheets/home.scss | 3 +++ app/controllers/home_controller.rb | 10 ++++++++++ app/helpers/home_helper.rb | 2 ++ app/views/home/index.html.erb | 2 ++ config/initializers/rails_admin.rb | 11 +++++++---- config/routes.rb | 2 ++ db/migrate/20170715175243_add_devise_to_users.rb | 1 + db/schema.rb | 1 + test/controllers/home_controller_test.rb | 9 +++++++++ 10 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/home.coffee create mode 100644 app/assets/stylesheets/home.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/views/home/index.html.erb create mode 100644 test/controllers/home_controller_test.rb diff --git a/app/assets/javascripts/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/home.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000..7131aac --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..97d779c --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,10 @@ +class HomeController < ApplicationController + + def index + + end + + def show + + end +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..2085730 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,2 @@ +

Home#index

+

Find me in app/views/home/index.html.erb

diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb index 570a244..1a6a6ed 100644 --- a/config/initializers/rails_admin.rb +++ b/config/initializers/rails_admin.rb @@ -2,11 +2,14 @@ ### Popular gems integration + config.authorize_with do + redirect_to main_app.root_path unless warden.user.admin == true + end ## == Devise == - # config.authenticate_with do - # warden.authenticate! scope: :user - # end - # config.current_user_method(&:current_user) + config.authenticate_with do + warden.authenticate! scope: :user + end + config.current_user_method(&:current_user) ## == Cancan == # config.authorize_with :cancan diff --git a/config/routes.rb b/config/routes.rb index 54a99e4..53ea7f2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + root 'home#index' + devise_for :users mount RailsAdmin::Engine => '/admin', as: 'rails_admin' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html diff --git a/db/migrate/20170715175243_add_devise_to_users.rb b/db/migrate/20170715175243_add_devise_to_users.rb index 21fdd55..545e5e9 100644 --- a/db/migrate/20170715175243_add_devise_to_users.rb +++ b/db/migrate/20170715175243_add_devise_to_users.rb @@ -2,6 +2,7 @@ class AddDeviseToUsers < ActiveRecord::Migration[5.1] def self.up change_table :users do |t| ## Database authenticatable + t.boolean :admin t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" diff --git a/db/schema.rb b/db/schema.rb index 7b14ba0..980aacb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -51,6 +51,7 @@ create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "admin" t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 0000000..6013b68 --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class HomeControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get home_index_url + assert_response :success + end + +end