-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
``` $ rails generate administrate:install Running via Spring preloader in process 30795 route namespace :admin do resources :blogs root to: "blogs#index" end WARNING: Unable to generate a dashboard for PaperTrail::Version. Administrate does not yet support namespaced models. create app/controllers/admin/application_controller.rb create app/dashboards/blog_dashboard.rb create app/controllers/admin/blogs_controller.rb ```
- Loading branch information
1 parent
56df062
commit b546a2b
Showing
6 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# All Administrate controllers inherit from this `Admin::ApplicationController`, | ||
# making it the ideal place to put authentication logic or other | ||
# before_actions. | ||
# | ||
# If you want to add pagination or other controller-level concerns, | ||
# you're free to overwrite the RESTful controller actions. | ||
module Admin | ||
class ApplicationController < Administrate::ApplicationController | ||
before_action :authenticate_admin | ||
|
||
def authenticate_admin | ||
# TODO Add authentication logic here. | ||
end | ||
|
||
# Override this value to specify the number of elements to display at a time | ||
# on index pages. Defaults to 20. | ||
# def records_per_page | ||
# params[:per_page] || 20 | ||
# end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Admin | ||
class BlogsController < Admin::ApplicationController | ||
# To customize the behavior of this controller, | ||
# you can overwrite any of the RESTful actions. For example: | ||
# | ||
# def index | ||
# super | ||
# @resources = Blog. | ||
# page(params[:page]). | ||
# per(10) | ||
# end | ||
|
||
# Define a custom finder by overriding the `find_resource` method: | ||
# def find_resource(param) | ||
# Blog.find_by!(slug: param) | ||
# end | ||
|
||
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions | ||
# for more information | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require "administrate/base_dashboard" | ||
|
||
class BlogDashboard < Administrate::BaseDashboard | ||
# ATTRIBUTE_TYPES | ||
# a hash that describes the type of each of the model's fields. | ||
# | ||
# Each different type represents an Administrate::Field object, | ||
# which determines how the attribute is displayed | ||
# on pages throughout the dashboard. | ||
ATTRIBUTE_TYPES = { | ||
versions: Field::HasMany.with_options(class_name: "PaperTrail::Version"), | ||
id: Field::Number, | ||
title: Field::String, | ||
body: Field::Text, | ||
created_at: Field::DateTime, | ||
updated_at: Field::DateTime, | ||
}.freeze | ||
|
||
# COLLECTION_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's index page. | ||
# | ||
# By default, it's limited to four items to reduce clutter on index pages. | ||
# Feel free to add, remove, or rearrange items. | ||
COLLECTION_ATTRIBUTES = [ | ||
:versions, | ||
:id, | ||
:title, | ||
:body, | ||
].freeze | ||
|
||
# SHOW_PAGE_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's show page. | ||
SHOW_PAGE_ATTRIBUTES = [ | ||
:versions, | ||
:id, | ||
:title, | ||
:body, | ||
:created_at, | ||
:updated_at, | ||
].freeze | ||
|
||
# FORM_ATTRIBUTES | ||
# an array of attributes that will be displayed | ||
# on the model's form (`new` and `edit`) pages. | ||
FORM_ATTRIBUTES = [ | ||
:versions, | ||
:title, | ||
:body, | ||
].freeze | ||
|
||
# Overwrite this method to customize how blogs are displayed | ||
# across all pages of the admin dashboard. | ||
# | ||
# def display_resource(blog) | ||
# "Blog ##{blog.id}" | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
Rails.application.routes.draw do | ||
namespace :admin do | ||
resources :blogs | ||
|
||
root to: "blogs#index" | ||
end | ||
resources :blogs | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
end |