Skip to content

Instantly share code, notes, and snippets.

@carlosramireziii
Last active May 19, 2021 17:53
Show Gist options
  • Select an option

  • Save carlosramireziii/651062e9fb434543a5865a9fc48aaee8 to your computer and use it in GitHub Desktop.

Select an option

Save carlosramireziii/651062e9fb434543a5865a9fc48aaee8 to your computer and use it in GitHub Desktop.

Revisions

  1. carlosramireziii revised this gist Jul 1, 2017. No changes.
  2. carlosramireziii revised this gist Jul 1, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion base_controller.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # app/controllers/admin/base_controller.rb

    # Inherit directly from ActionController::Base rather than ApplicationController to ensure clean separate
    # Inherit directly from ActionController::Base rather than ApplicationController to ensure clean separation
    class Admin::BaseController < ActionController::Base
    # use an admin-specific layout instead of the main application layout
    layout "admin"
  3. carlosramireziii revised this gist Apr 18, 2017. 5 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  4. carlosramireziii created this gist Apr 18, 2017.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # app/controllers/admin/base_controller.rb

    # Inherit directly from ActionController::Base rather than ApplicationController to ensure clean separate
    class Admin::BaseController < ActionController::Base
    # use an admin-specific layout instead of the main application layout
    layout "admin"

    # all child controllers will automatically enforce access to admins only
    before_action :require_admin

    def require_admin
    # ...
    end
    end
    8 changes: 8 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # app/controllers/admin/articles_controller.rb

    # Note the namespacing and the inheritance
    class Admin::ArticlesController < Admin::BaseController
    def index
    @articles = Article.all
    end
    end
    21 changes: 21 additions & 0 deletions gistfile3.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <% # app/views/layouts/admin.html.erb %>

    <!DOCTYPE html>
    <html>
    <head>
    <title>Admin Interface</title>
    <%= csrf_meta_tags %>

    <% # Optionally use admin-specific assets here instead of the normal application assets %>
    <%= stylesheet_link_tag 'admin', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'admin', 'data-turbolinks-track': 'reload' %>
    </head>

    <header>
    <h1>Welcome Admin User</h1>
    </header>

    <body>
    <%= yield %>
    </body>
    </html>
    7 changes: 7 additions & 0 deletions gistfile4.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # config/initializers/assets.rb

    # ...

    # Precompile additional assets.
    # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
    Rails.application.config.assets.precompile += %w( admin.js admin.css )
    9 changes: 9 additions & 0 deletions gistfile5.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # config/routes.rb

    Rails.application.routes.draw do
    namespace :admin do
    resources :articles
    end

    # ...
    end